dtsc14683 2012-09-23 08:58
浏览 115
已采纳

使用PHP + MySql的投票系统?

We have to make a ballot system that makes users vote for various candidates on different positions. There's a login for voters. How do you store a vote of one voter and then get that vote added to the previous votes? The only possible way is to store every vote on a database right? But what would the structure of the database look like? And how do you count it?

edit:
The voting system doesnt only have one group of candidates to vote. It has mayor, vice-mayor, senator, etc. There are too many. that's why I'm confused. If only it was just a voting system of a president, it would be easier. So if I have a table for the voter, with a column of his/her voted candidate, it's not possible since the voter votes for many candidates.

  • 写回答

5条回答 默认 最新

  • dongle2627 2012-09-23 09:07
    关注

    A better way would be to have a different table to store Votes. And that table will have two attributes (VoterId, CandidateId) And you can fetch the Vote Count if you are allowing multiple votes from this table..

    But it would be better to make VoterId a Primary key in this table.. To avoid multiple voting

    CandidateType: - (TypeId(PK), typeName, maxVotePerVoterForThisType)

    Voter Table: - (voterId(PK), voterName, otherInfo)

    Candidate Table: - (candidateId(PK), candidateName, constituency, otherInfo, TypeId(FK))

    Votes:- (voterId(PK, FK), TypeId(PK, FK), candidateId(FK))

    *EDIT:- Schema edited with changed requirement in original post

    *EDIT: - Added a field in CandidateType table to allow multiple votes.(E.g.: Now a voter can vote for 10 Senators, if maxVotePerVoter for this type is set to 10..)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误