I'm doing a personal project where I have a quiz with a number of boolean questions. Each question will have a two answer choices "true" and "false". Based on the selected answer, a new question will be asked with the similar pattern and based on that an another question. Any question may have any or no number of sub-questions.
The last questions in the tree (E, D) and questions with no sub-questions (F) will also store the correct answer from either "true" or "false".
The alphabets A,B,C,D,E,F are questions. A quiz can have any number of master questions (like A), sub-questions like (like B,C,D,E) and individual questions (like F).
Kindly help me design a simple database schema for for this kind of quiz. I'm open to both relational (mysql) and document (mongodb) databases.
concept diagram
-
this doesn't help you writing the code, but tools such as Survey Gizmo and Survey Monkey can do this for you, if that's an option.DForck42– DForck422015年01月15日 22:09:33 +00:00Commented Jan 15, 2015 at 22:09
-
what doesn't help? Survey Monkey or any other quiz platform outside is not an option.Navi– Navi2015年01月20日 08:31:19 +00:00Commented Jan 20, 2015 at 8:31
3 Answers 3
In relational database, you should create a table called Questions which should contain following fields:
ID
QuestionString
QuestionType
(Master, Individual, sub-question)TrueCase
(here you should store the ID of the next question. Since we'll store all questions in this table, therefore each questions shall have unique ID)FalseCase
(ID of the question to ask if answer is not correct. If ID is null, then you should exit)
Hope it helps.
* User
- user_id auto integer
- regtime datetime
- username varchar
- useremail varchar
- userpass varchar
* Question
- question_id auto integer
- question varchar
- is_active enum(0,1)
* Question_choices
- choice_id auto integer
- question_id integer
- is_right_choice enum(0,1)
- choice varchar
* User_question_answer
- user_id integer
- question_id integer
- choice_id integer
- is_right enum(0,1)
- answer_time datetime
-
Please explain it a bit and show the relations between the tables.András Váczi– András Váczi2015年06月25日 16:29:00 +00:00Commented Jun 25, 2015 at 16:29
I have an idea about mongoDB.
You can pre-create the quiz by using as field names the correct answer (true or false). When the player gives an answer you will have to check if the field exists. An example document is the below one:
{Question:"":{true:{Question:{"text goes here",false:{}...}}}
So if he answer true the first in order to validate you have to check if the document Question.true exists. If is the correct answer was true and the next answer is false you have to check if Question.true.false exists...
-
Thanks Antonis, I didn't get what you said after reading for the first time. I'll spend some more time analyzing your suggestion.Navi– Navi2015年01月16日 11:20:14 +00:00Commented Jan 16, 2015 at 11:20
-
No worries, i am much better with drawing than writing. In general the idea is nested documents and for field name of each nested document use the correct answer of the previous question. Its like following a hierarchical tree with two branches (true,false) but always only the "correct branch" is present. We can discuss this further on the chat if you like.Antonios– Antonios2015年01月20日 03:36:49 +00:00Commented Jan 20, 2015 at 3:36
-
thats fine but it seems mongodb is not the right database to get 10 random quiz questions for a user without repetition till all options are exhaustedPirateApp– PirateApp2017年02月24日 12:22:47 +00:00Commented Feb 24, 2017 at 12:22