Quiz Answers (cant find)

Quiz Answers (cant find)

deur Jason Lea -
Getal antwoorde: 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

Gemiddeld van beoordelings: -
In antwoord op Jason Lea

Re: Quiz Answers (cant find)

deur Joseph Rézeau -
Prentjie van Core developers Prentjie van Particularly helpful Moodlers Prentjie van Plugin developers Prentjie van Testers Prentjie van Translators
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
Gemiddeld van beoordelings: -
In antwoord op Joseph Rézeau

Re: Quiz Answers (cant find)

deur Tim Hunt -
Prentjie van Core developers Prentjie van Documentation writers Prentjie van Particularly helpful Moodlers Prentjie van Peer reviewers Prentjie van Plugin developers
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.
Gemiddeld van beoordelings:Useful (2)
In antwoord op Tim Hunt

Re: Quiz Answers (cant find)

deur 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?
Gemiddeld van beoordelings: -
In antwoord op Jason Lea

Re: Quiz Answers (cant find)

deur Tim Hunt -
Prentjie van Core developers Prentjie van Documentation writers Prentjie van Particularly helpful Moodlers Prentjie van Peer reviewers Prentjie van Plugin developers
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.
Gemiddeld van beoordelings: -
In antwoord op Tim Hunt

Re: Quiz Answers (cant find)

deur 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. glimlag

Gemiddeld van beoordelings: -
In antwoord op Jason Lea

Re: Quiz Answers (cant find)

deur Tim Hunt -
Prentjie van Core developers Prentjie van Documentation writers Prentjie van Particularly helpful Moodlers Prentjie van Peer reviewers Prentjie van Plugin developers
Right, so for essay questions, the HTML they type is in question_states.answers. You just need to find the right rows!
Gemiddeld van beoordelings: -
In antwoord op Tim Hunt

Re: Quiz Answers (cant find)

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

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 glimlag *
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 glimlag

Regards
Gemiddeld van beoordelings: -
In antwoord op Jason Lea

Re: Quiz Answers (cant find)

deur Tim Hunt -
Prentjie van Core developers Prentjie van Documentation writers Prentjie van Particularly helpful Moodlers Prentjie van Peer reviewers Prentjie van Plugin developers
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.
Gemiddeld van beoordelings: -
In antwoord op Tim Hunt

Re: Quiz Answers (cant find)

deur Jason Lea -
Where's that if u don't mind me asking...
Gemiddeld van beoordelings: -
In antwoord op Jason Lea

Re: Quiz Answers (cant find)

deur Tim Hunt -
Prentjie van Core developers Prentjie van Documentation writers Prentjie van Particularly helpful Moodlers Prentjie van Peer reviewers Prentjie van Plugin developers
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.
Gemiddeld van beoordelings: -
In antwoord op Tim Hunt

Re: Quiz Answers (cant find)

deur 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 glimlag

How do you know so much about moodle
Gemiddeld van beoordelings: -
In antwoord op Jason Lea

Re: Quiz Answers (cant find)

deur Tim Hunt -
Prentjie van Core developers Prentjie van Documentation writers Prentjie van Particularly helpful Moodlers Prentjie van Peer reviewers Prentjie van Plugin developers
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.
Gemiddeld van beoordelings: -
In antwoord op Tim Hunt

Re: Quiz Answers (cant find)

deur Jason Lea -
Wow so you must know moodle backwards glimlag
Thanx again for the help
Gemiddeld van beoordelings: -
In antwoord op Tim Hunt

Re: Quiz Answers (cant find)

deur 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
Gemiddeld van beoordelings: -