使用PHP和MySQL开发'Quiz'Web应用程序的数据库设计 [英] Database Design For Developing 'Quiz' Web Application using PHP and MySQL
问题描述
所以,我试图学习PHP和MySQL(我有一个基本的了解;我已经阅读了头一个SQL和头一个PHP和MySQL的前半部分),我认为最好的方法通过构建一些东西而不是阅读来巩固我的知识。
So, I'm trying to learn PHP and MySQL (I have a basic understanding of both; I've read the first half of both Head First SQL and Head First PHP & MySQL) and I figure the best way to solidify my knowledge is by building something rather than reading.
考虑到这一点,我想创建一个连接到服务器上的MySQL数据库的基本网页。我将构建一个基本的HTML表单,并允许用户输入基本信息,例如:last_name,first_name,email,birthday,gender。
With that in mind, I would like to create a basic webpage that connects to a MySQL database on a server. I will build a basic HTML form and allow users to input basic information, such as: last_name, first_name, email, birthday, gender.
/ strong>我不知道如何设计一个数据库,将记录一个基本的测验的结果 - 我只想5个选择题。最后,我想显示用户的结果和以前的用户的结果。
My problem is I don't know how to design a database that will record the results of a basic quiz - I want just 5 multiple-choice problems. Eventually, I would like to display the results of the user versus the previous users' results.
如果你能帮助我理解如何设计一个5问题测验的表格,我会很感激。谢谢!
If you could help me understand how to design table(s) for a 5-question Quiz I'd appreciate it. Thanks!
推荐答案
我将从4个简单的表开始:
I would start with 4 simple table:
* 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
设计是:
- 表
用户
用于存储注册用户。
- 表
问题
用于存储您的所有问题。它具有is_active,以便您可以有选择地仅显示活动问题(使用WHERE is_active ='1'
) - c> question_choices 用于存储所有可用的选项。
is_right_choice
它定义了什么选择是特定问题的正确答案。 - 表
User_question_answer
用于存储您的用户的答案。它有is_right
更快的查找,看看特定的问题和答案选择是否正确(基于is_right_choice
之前定义)。它还有answer_time
只是为了注意特定用户回答问题。
- table
User
is for storing registered user. - table
Question
is for storing all your question. It has is_active so that you can selectively display only active question (usingWHERE is_active = '1'
) - table
question_choices
is for storing all available options. It hasis_right_choice
which define what choice is the right answer for particular question. - Table
User_question_answer
is for storing answer from your user. It hasis_right
for faster lookup, to see whether that particular question and answer choice is right (based onis_right_choice
previously defined). It also hasanswer_time
just to note when that particular user answer the question.
这篇关于使用PHP和MySQL开发'Quiz'Web应用程序的数据库设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!