duanshaiduhao2471 2014-01-11 18:44
浏览 12
已采纳

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

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

  • 写回答

1条回答 默认 最新

  • douhuan6305 2014-01-11 18:50
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan