dagnasty Posted August 7, 2006 Share Posted August 7, 2006 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 ................ votedbyso 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 https://forums.phpfreaks.com/topic/16764-mysql-question-regarding-efficiency/ Share on other sites More sharing options...
corbin Posted August 7, 2006 Share Posted August 7, 2006 i would build the table likepoll_id - user - voted_option23 Corbin blue27 Fred greeenand 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 https://forums.phpfreaks.com/topic/16764-mysql-question-regarding-efficiency/#findComment-70508 Share on other sites More sharing options...
dagnasty Posted August 7, 2006 Author Share Posted August 7, 2006 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 https://forums.phpfreaks.com/topic/16764-mysql-question-regarding-efficiency/#findComment-70511 Share on other sites More sharing options...
tomfmason Posted August 7, 2006 Share Posted August 7, 2006 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 votesI would then have in the votes tablevote_idPoll_idusername or user_idThen 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 https://forums.phpfreaks.com/topic/16764-mysql-question-regarding-efficiency/#findComment-70513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.