Jump to content

Voting System with Users


zachninme

Recommended Posts

Hello.I am working on something where I want my users to be able to vote on numerous submitted items. I also want to make sure that no one votes twice or anything.How should I set up my tables to disallow users from voting more than once on each item?Thanks in advanced!

Link to comment
Share on other sites

If the user who can vote will be a registered member of your website, then we can restrict by getting the unique user id and storing it in a database along with the survey or poll id which he already voted....If not [anybody can vote] then some ways are by getting user's IP and storing in DB....or creating cookies and checking them. This has few problems as user can work around and vote multiple times... not fool-proof.....

Link to comment
Share on other sites

You simply have to create a combined(i dont know if thats the correct english term, but anyway) primary key, composed of the userID and the pollID, or itemID, or whatever you want to name the object ppl want to vote for. that way, a user can vote for multiple subjects, su subject can be voted by multiple users, but a user wont be able to vote multiple time for the same subject, because it would be trying to create a duplication of the primary key. i you want to let the user to change his vote, then you have to do it with an update query.

Link to comment
Share on other sites

If you want a totally normalised database system it would be wiser to control and restrict the user entries to the poll using the interfase (php, VB, perl, whatever you might be using) I would suggest making the following tables:users (establishes existing users)polls (establishes existing polls)usersPolls (relates users to polls)pollData (contains all polls questions)pollAnswers (relates possible answers to polls)pollResults (relates users to answers to polls)in users you have for example: (primary key idUser)idUserfirstnameemailin polls you have for example: (primary key idPoll)idPollpollnamedescriptionidCreateUserin usersPolls you put the following: (no primary key, this will allow users to participate in various polls)idUseridPollin pollData you place the following: (primary key idQuestion, this makes each question in the DB unique... idPoll refers to the poll it belongs to)idQuestionidPollquestionin pollAnswers you place the following: (primary key idAnswer, this allows many answers per poll and related each answer to a poll number)idAnsweridPollin pollResults you place the following: (no primary key)idUseridPollidAnswerNow what you do is in the interfase, after logging in with a user or something, when this person enters a poll it verifies userPolls and if the person is not related to a poll yet then allow him/her to view questions, upon answering it adds the user/poll to userPolls and adds the user/poll/answer id to pollResults... this way you are controlling all with the interfase and maintaining a good nice clean and normalised DB.I'm not entirely sure people about this one but in my experience normalising tables has been great and I couldn't have normalised this situation any better ;Ptell me what you think -miffe

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...