Jump to content

MySQL Question regarding efficiency.


dagnasty

Recommended Posts

If I have a voting system, am anticipating thousands of polls, and each poll has a unique poll number in the database, and members (logged in) are only allowed 1 vote per poll. Would putting a votedby column for each poll.

Such as:

pollname      pollnumber  ................        votedby
so and so..  45345        ................        john34,bill44,joe,brandon366,

and code such as:(psuedo)

if $myusername."," is located in votedby
{
don't allow voting
}else {
allow voting
}


Be the most efficient way of keeping track of the users who voted on it and preventing them from doing it again?

How would you do it?
Link to comment
Share on other sites

i would build the table like

poll_id - user - voted_option
23        Corbin    blue
27        Fred      greeen


and so on... but thats not very efficient at all... I cant think of any other way to do it that would be more efficient though...
Link to comment
Share on other sites

What they voted for need not be logged as it wont be displayed anywhere and isn't relevant.

The poll's row where "votedby" is going to be pulled from the database to show the poll anyway, so would it be more efficient to do a "find $username with comma after it in the votedby string" or a

select * where user = $username and pollnumber = $pollnumber

?
Link to comment
Share on other sites

The way that I would do it(not sure if it is more efficient or not )

I would create two tables one polls, with all the poll data , and the other votes
I would then have in the votes table

vote_id
Poll_id
username or user_id

Then before I posted a vote I would search the table like this

[code=php:0]"SELECT COUNT(*) as `vote_match` FROM `votes` WHERE `poll_id` = '$poll_id' AND `username` = '$username'"[/code]

Hope that helps,
Tom
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.