我想创建一个简单的轮询管理器(PHP和Apache)。
我想要例如选项:
- 是或否(数据库中的布尔值)
- 使用自己的选项进行选择(?)
- answerbox(varchar 5000)
主持人可以选择创建新的池。例如,他想要
- 两个是或否
- 一次选择
- 两个答案框
如何将其保存在数据库中?我不知道:(
以下是如何实现它的示例:
两种类型的问题——select
(包括是/否问题)和text
:
question_types
--------------
id type
--------------
1 select
2 text
表selects
存储所选问题类型的所有选项:
selects
---------------------------------------------
id select_id option_desc
---------------------------------------------
1 1 yes
2 1 no
2001 500 optionX
2002 500 optionY
表polls
存储民意调查数据——每个答案的行,参考选择问题的selects
表。根据您的示例填写:
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
表answers
存储用户的答案。回答栏参考selects.id
用于选择问题,参考answers_texts.id
用于文本问题:
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
answer_texts
表格存储文本问题的答案:
answers_texts
-----------------
id answer
-----------------
301 text1
302 text2