简体   繁体   中英

Normalized Database schema of quiz in php

I am little confusing for building schema of quiz

In this I have to upload many questions and having four options each option contains textbox and corresponding checkbox that denotes for right answer. if admin select one checkbox that could be right answer.

Note:- In some cases I have uploaded many option 6 to 7 and answers might be 2 or 3 are correct and admin will click on many checkboxes

在此处输入图片说明

Can anyone helping in schema

This seems fairly straight forward. You just have three tables, one for quizzes, one for questions and one for answers. Something like this:

Quizzes

+----+-------------+-----------------+
| id |    name     |   description   |
+----+-------------+-----------------+
|  1 | Sample Quiz | An example quiz |
+----+-------------+-----------------+

Questions

+----+---------+------------+
| id | quiz_id |  question  |
+----+---------+------------+
|  1 |       1 | Question 1 |
+----+---------+------------+

Answers

+----+-------------+----------+------------+
| id | question_id |  answer  | is_correct |
+----+-------------+----------+------------+
|  1 |           1 | Answer 1 |          0 |
|  2 |           1 | Answer 2 |          1 |
|  3 |           1 | Answer 3 |          0 |
|  4 |           1 | Answer 4 |          0 |
+----+-------------+----------+------------+

This schema will support as many quizzes as you need, each with any number of questions and each question can have any number of answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM