General help

Quiz storage in database

 
Picture of Mohanish Nagarkar
Quiz storage in database
 

I have been trying to understand the flow of quiz creation and it already took me a lot of time understanding the association between tables used to fetch questions from the database as per my requirement.

What I did not understand is after selecting the questions to be added to a quiz, where does that data go?

Considering an easy flow, we give a name to the quiz, add questions and then there is a record in the database with a unique quiz id and the list of questions in that quiz. But that is not the case with moodle or rather moodle database.

Can anybody give me a detailed walk-through of the flow of quiz creation, where are the questions for a particular quiz (say quiz id is 10) stored and how the association is carried out between multiple tables included in this process.


Thanks,

Mohanish

 
Average of ratings: -
Picture of Pradeep Bisht
Re: Quiz storage in database
 

Hi Mohanish,

quiz creation process are below :-

first  enter in your course and enable  editing mode by click right top corner and click Turn editing off.

your course open in editing mode, then click Add an activity or resource   .

one pop up open there you can choose quiz radio button . just click on this and fill the form .after this process you see quiz is create in your course .


Thanks

 
Average of ratings: -
Picture of Mohanish Nagarkar
Re: Quiz storage in database
 

Thanks Pradeep, but I think you got my question wrong.

I have understood the flow that is shown on the browser. What I want to know is the process that runs in the back-end.

Which tables are modified/changed when we add questions to a quiz, where is the quiz data stored.


I'll give you a scenario.

I created a quiz named Exercise 1 and then I added 5 questions to the quiz.

Suppose the quiz id for Exercise 1 is 10. And the 5 questions that I added to the quiz have IDs 1,2,3,4,5 respectively.

All I want to know is which table shows the association between the quiz id and questions i.e.

Quiz ID     Quiz Name     Questions

10              Exercise 1        1,2,3,4,5


Is there any such structure created in the database? If yes then where and if no then how else is the data stored?

Thanks.
 
Average of ratings: -
Picture of Pradeep Bisht
Re: Quiz storage in database
 

Hi,

Below are  quiz related database table 

 mdl_quiz

 mdl_quiz_feedback

 mdl_quiz_sections 


look above table then you easily understand relationship between that tables .

Thanks

 
Average of ratings: -
Picture of C Behan
Re: Quiz storage in database
Particularly helpful Moodlers

You can view the database schema from here: https://docs.moodle.org/dev/Database_Schema#Moodle_3.2


This query will give you the questions in a given quiz - you might find it useful to look at the inner joins. 


SELECT prefix_question.id AS ID, prefix_question.name AS "Question Name", prefix_question.questiontext AS Question FROM prefix_question
INNER JOIN prefix_quiz_slots ON prefix_question.id=prefix_quiz_slots.questionid
INNER JOIN prefix_quiz ON prefix_quiz.id=prefix_quiz_slots.quizid
INNER JOIN prefix_course_modules ON prefix_course_modules.instance=prefix_quiz.id
WHERE prefix_course_modules.id=XXX

(XXX is the idnumber at the end of the URL for the quiz).
 
Average of ratings: -
Picture of Mohanish Nagarkar
Re: Quiz storage in database
 
Thanks C,

I tried this but it gave me no result.

I modified the query according to the prefix of the database and put the quiz id of one of the quizzes, but it is giving me an empty set. I am adding some screenshots for you to check if I'm doing anything wrong.


There is a course named 'Chemistry' in my table, having id as 14 and there's a sub-category named 'Chemistry in Action' having id 451. Inside it is a quiz 'Level - 1' having id 452.


Here's the list of quizzes in my quiz table, corresponding to the course shown in the previous image.



When I run the query you told me, I don't get any results.




Am I going wrong anywhere?

 
Average of ratings: -
Picture of C Behan
Re: Quiz storage in database
Particularly helpful Moodlers

Hi Mohanish,


If I understand you correctly, you should be using 452 at the end of your query (rather than 215).


If you click on the quiz, the URL will be https://YourMoodleSite/mod/quiz/view.php?id=XXX

XXX should be the number at the end of your query.


Catherine

 
Average of ratings: -
Picture of Mohanish Nagarkar
Re: Quiz storage in database
 

Hi Catherine,


Really sorry for creating confusion, 215 is also a quiz id. So basically any quiz id I pass, it does not give me any data. Returns 0 records.


Mohanish

 
Average of ratings: -