douliaotong4944 2013-03-26 09:49
浏览 48
已采纳

将测试结果保存到数据库:保持数据库整洁[关闭]

I've created a test system using Wordpress, jQuery and PHP which is working great. The area that I don't have much experience in is mysql databases.

I'm not really sure how to save the results in a neat and tidy way.

The things I want to save are the following:

  1. Users name.
  2. Test name.
  3. Questions.
  4. Answers.
  5. Score.
  6. Pass/fail.

Points 1, 2, 5 & 6 are fairly straight forward to save the data. The confusion comes with the questions and answers.

How can I save these in a neat way to the mysql database?

Say there are 10 questions, each with multiple choice answers, how can I save each of those in the database but have it linked to the user that filled them in? I'm not sure how to keep the database neat and this could quickly spiral out of control.

In the future I may want to do some searching on the those questions and answers.

  • 写回答

3条回答 默认 最新

  • dsfdsfsdf45489 2013-03-26 10:01
    关注

    You need to normalize your database structure.

    **Table: users**
    id - int
    username - varchar
    password - varchar
    active - enum (y,n)
    
    **Table: questions**
    id - int
    question - varchar/text
    
    **Table: answers**
    id - int
    question_id - int (foreign key questions.id)
    answer - varchar/text
    is_correct_anser - enum (y, n)
    
    **Table: test_master**
    id - int
    test_name - varchar/text
    pass_score - int (minimum score required to pass the test)
    
    **Table: test**
    user_id - int (foreign key to users.id)
    test_id - int (foreign key to test_master.id)
    question_id - int (foreign key to questions.id)
    answer_id - int (foreign key to answers.id)
    

    Based on above tables, you can store all required information in in normalized way. Please note that, normalization will not always help and it depends on your application's requirement. It is also a better ideal to store total score in a separate table along with user_id and test_id once test is completed as this will avoid joins on multiple table.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口