Quiz Answers (cant find)

Quiz Answers (cant find)

Jason Lea -
Erantzun kopurua: 16
I'm trying to build a report that will display students and there answers from quizzes that they have already completed. But am unsure which moodle database table is used to store the answers.

Some help or advice would be much appreaciated smile

Regards

Puntuazioen batez bestekoa: -
Jason Lea(e)ri erantzunda

Re: Quiz Answers (cant find)

Joseph Rézeau -
Core developers-ren irudia Particularly helpful Moodlers-ren irudia Plugin developers-ren irudia Testers-ren irudia Translators-ren irudia
Jason : I'm trying to build a report that will display students and their answers from quizzes that they have already completed.

But this already exists in standard Moodle. Why do you want to re-invent the wheel?

Joseph
Joseph Rézeau(e)ri erantzunda

Re: Quiz Answers (cant find)

Tim Hunt -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia
Actually the report Jason wants is the 'Detailed responses' report, which is a third-party plugin in Moodle 1.9 and before, but has been added to core for moodle 2.0.
Puntuazioen batez bestekoa:Useful (2)
Tim Hunt(e)ri erantzunda

Re: Quiz Answers (cant find)

Jason Lea -
I dont really mind doing the code to develop the report, just interested to know about the mdl_question_states:
I see the one column is called answer, that i would assume contains the answers to the quiz. But the 'answer' column in filled with random numbers.

Is there a way to get the actual answers frm the table that the student entered in the quiz?
Jason Lea(e)ri erantzunda

Re: Quiz Answers (cant find)

Tim Hunt -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia
Well, question_states.answer contains question-type specific information. For multiple-choice questions, the seemingly random numbers relate to the question_answers table. Development:Quiz_database_structure may help.
Tim Hunt(e)ri erantzunda

Re: Quiz Answers (cant find)

Jason Lea -
Ok great thanx for that link, will come in handy.
But i actually wasn't specific enough in my post.
On our site we have a student feedback(survey) quiz which is available to students to compete(used for our marketing department). It contains a number of questions and the students reply to each question by entering there HTML editor box.

I'm interested to know what table in the moodle database it is stored in. irribarrea

Jason Lea(e)ri erantzunda

Re: Quiz Answers (cant find)

Tim Hunt -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia
Right, so for essay questions, the HTML they type is in question_states.answers. You just need to find the right rows!
Tim Hunt(e)ri erantzunda

Re: Quiz Answers (cant find)

Jason Lea -
thanx for helping me out with this, only got about 3 months experience of moodle under my belt. irribarrea

There are 2 queries from me:
1: i'm get getting multiple rows for one student,
this is the current sql i'm using, it obviously is incorrect and needs to be edited:

SELECT DISTINCT q.id AS 'quiz id', q.course AS 'course id', q.name AS 'quiz name', qs.answer AS 'answers', qa.userid AS 'user id', u.firstname, u.lastname
FROM mdl_quiz q
LEFT JOIN mdl_quiz_attempts qa
ON q.id = qa.quiz
LEFT JOIN mdl_user u
ON u.id = qa.userid
LEFT JOIN mdl_question_states qs
ON qs.question = q.id
WHERE qa.quiz = 49
AND qa.attempt = 1
AND u.id = 758

*This query is just for reference irribarrea *
Thank you for that table structure diagram of moodle quiz tables.

2: The column called 'answers' in mdl_question_states, it contains nothing but numbers.
How do i extract the actual answer the student entered into the quiz?

Thanx for all ur help irribarrea

Regards
Jason Lea(e)ri erantzunda

Re: Quiz Answers (cant find)

Tim Hunt -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia
Did you follow the link from the quiz DB docs to the question bank DB docs? That question DB page contains a very useful query.
Tim Hunt(e)ri erantzunda

Re: Quiz Answers (cant find)

Jason Lea -
Where's that if u don't mind me asking...
Jason Lea(e)ri erantzunda

Re: Quiz Answers (cant find)

Tim Hunt -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia
Development:Question_database_structure#Following_what_happens_when_questions_are_attempted

You probably want either the newest or newgraded state from each question.

Also, you will need to add in

JOIN mdl_quiz_attempts qa ON qa.uniqueid = st.attempt

so you can extract only the attempts for the values of qa.quiz that you are interested in.
Tim Hunt(e)ri erantzunda

Re: Quiz Answers (cant find)

Jason Lea -
You are an absolute star!! big grin
That join made the difference
The get the correct number of rows for each student.

Thank you so much irribarrea

How do you know so much about moodle
Jason Lea(e)ri erantzunda

Re: Quiz Answers (cant find)

Tim Hunt -
Core developers-ren irudia Documentation writers-ren irudia Particularly helpful Moodlers-ren irudia Peer reviewers-ren irudia Plugin developers-ren irudia
Well, I have been a full time Moodle developer for 3.5 years, first at the OU, then at Moodle.com. And for most of that time, the Quiz has been my responsibility. It is very nice to be paid to work full time on Moodle.
Tim Hunt(e)ri erantzunda

Re: Quiz Answers (cant find)

Jason Lea -
Ah!
I've got the answers, have have far too many rows for each student, 766 rows.
May need to change the structure of my query

SELECT DISTINCT qa.userid AS 'user id', q.id AS 'quiz id', q.course AS 'course id', u.firstname, u.lastname, qs.answer AS 'answers'
FROM mdl_quiz_question_instances qqi
LEFT JOIN mdl_quiz q
ON qqi.quiz = q.id
LEFT JOIN mdl_quiz_attempts qa
ON qa.quiz = q.id
LEFT JOIN mdl_question quest
ON quest.id = qqi.question
LEFT JOIN mdl_question_states qs
ON qs.question = quest.id
LEFT JOIN mdl_user u
ON u.id = qa.userid
WHERE q.id = 49
AND qa.attempt = 1
AND u.id = 758