dtsc14683 2012-09-23 00:58
浏览 116
已采纳

使用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 01: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部