php mysql投票系统,使用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.

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值