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

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 :(

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