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.
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 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.
Below are quiz related database table
look above table then you easily understand relationship between that tables .
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.
(XXX is the idnumber at the end of the URL for the quiz).
SELECT prefix_question.id AS ID, prefix_question.name AS "Question Name", prefix_question.questiontext AS 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
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?
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.