Database Design For Developing 'Quiz' Web Application using PHP and MySQL

前端 未结 4 889
旧时难觅i
旧时难觅i 2020-12-22 18:40

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 t

4条回答
  •  执笔经年
    2020-12-22 19:05

    I would start with 4 simple tables:

     * 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
    

    My thought on this table design is:

    • table User is for storing registered user.
    • table Question is for storing all your questions. It has is_active so that you can selectively display only active questions (using WHERE is_active = '1')
    • table question_choices is for storing all available options. It has is_right_choice which defines what choice is the right answer for particular question.
    • Table User_question_answer is for storing answer from your user. It has is_right for faster lookup, to see whether that particular question and answer choice is right (based on is_right_choice previously defined). It also has answer_time just to note when that particular user answer the question.

提交回复
热议问题