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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度