doutuo7609 2012-01-14 02:28
浏览 7
已采纳

如何在数据库中保持民意调查? [关闭]

I would like create simply polls manager (PHP and Apache).

I want for example options:

  1. yes or no (boolean in database)
  2. select with own option (?)
  3. answerbox (varchar 5000)

Moderator have option create new pool. He want for example:

  • two yes or no
  • one select
  • two answer box.

How can i keep this in database? I dont have any idea :(

  • 写回答

1条回答 默认 最新

  • duancaishi1897 2012-01-14 04:02
    关注

    Here is an example of how it can be implemented:

    Two types of questions -- select (including yes/no questions) and text:

    question_types
    --------------
    id   type
    --------------
    1    select
    2    text
    

    Table selects stores all options for the select question type:

    selects
    ---------------------------------------------
    id   select_id option_desc
    ---------------------------------------------
    1    1         yes
    2    1         no
    2001 500       optionX
    2002 500       optionY
    

    Table polls stores polls data -- row for each answer with reference to selects table for select question. Filled according to your example:

    polls
    -----
    id poll_id type  select_id
    -----------------------------
    10 100     2     1
    11 100     2     1
    12 100     2     500
    13 100     3
    14 100     3
    

    Table answers stores user's answers. answer column references to selects.id for select questions and to answers_texts.id for texts questions:

    answers
    -----------------------------
    id user poll_row_id answer
    -----------------------------
    1  5000 10          1
    2  5000 11          2
    3  5000 12          2002
    4  5000 13          301
    5  5000 14          302
    

    The answer_texts tables stores answers to the text questions:

     answers_texts
     -----------------
     id  answer
     -----------------
     301 text1
     302 text2
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi