进行动态秸秆调查[关闭]

Im trying to make something like http://strawpoll.me/ for learning purposes. User creates a poll, so a poll can hold options as much as he wants to.

I think this shouldnt be a problem but I'm not sure how to set up polls in database. Is every poll creating a table for itself? Or are polls in the same table but are inserted by row with id? In that case I'm not sure how would i need to set up columns..

I need a hint to get me moving :)

Polls themselves are inside the table poll. There is another table called poll_option. Let's assume we have the following poll:

  • Name: Poll 1
  • Option 1: This is poll 1
  • Option 2: This is NOT poll 5

In poll, there'd be:

id, poll_name, date_created for example. poll_option would then contain id, option_name, poll_id. poll_id would be the poll this option is a part of.

There would of course be the need for voting, so a third table is needed: poll_votes. poll_vote merely contain id, date_created and user_id. user_id is either the IP, a cookie, or a session key of the user. Straw Poll saves a cookie called uid as to identify if you have already voted in this poll.

Putting it all together:

TABLE: poll
id | poll_name | date_created
62 | Poll 1    | 2014-01-11 12:34:56

TABLE: poll_option
id  | option_name        | poll_id
844 | This is poll 1     | 62
844 | This is NOT poll 5 | 62

TABLE: poll_vote
id   | user_id | date_created
1104 | 482424  | 2014-01-12 13:53:55