Jump to content


Photo

MySQL Question regarding efficiency.


  • Please log in to reply
3 replies to this topic

#1 dagnasty

dagnasty
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 07 August 2006 - 06:57 AM

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?

#2 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 07 August 2006 - 07:20 AM

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...
Why doesn't anyone ever say hi, hey, or whad up world?

#3 dagnasty

dagnasty
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 07 August 2006 - 07:27 AM

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

?

#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 07 August 2006 - 07:34 AM

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

"SELECT COUNT(*) as `vote_match` FROM `votes` WHERE `poll_id` = '$poll_id' AND `username` = '$username'"

Hope that helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users