bschvy Posted June 21, 2008 Share Posted June 21, 2008 If you have a website using php/mysql where people log in with a username and you want them to vote on a poll, what is the best approach to make sure each username gets one vote per poll? Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/ Share on other sites More sharing options...
keeB Posted June 22, 2008 Share Posted June 22, 2008 Database or PHP wise? Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571272 Share on other sites More sharing options...
bschvy Posted June 22, 2008 Author Share Posted June 22, 2008 Database wise Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571346 Share on other sites More sharing options...
keeB Posted June 22, 2008 Share Posted June 22, 2008 create table person ( Â userid int not null ); create table poll ( userid int references user(userid,; -- creates foreign key on user.userid other_columns text ); Â Load the poll, iterate through userId's. If any match current user's id, display error. Â Â Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571350 Share on other sites More sharing options...
dbo Posted June 22, 2008 Share Posted June 22, 2008 I would think you would just want to query the said poll table before allowing them to vote. If you know they are logged in you should have their user id. It should be a simple query of the poll table that determines whether or not that user id exists for the selected poll. There should not be any need to iterate over the list. Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571474 Share on other sites More sharing options...
bschvy Posted June 22, 2008 Author Share Posted June 22, 2008 Does this mean making a table for each poll that I have? Will that take up a lot of memory if there are many polls? Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571678 Share on other sites More sharing options...
dbo Posted June 22, 2008 Share Posted June 22, 2008 Nope, just need a poll id. Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571712 Share on other sites More sharing options...
bschvy Posted June 22, 2008 Author Share Posted June 22, 2008 cool, thanks Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571786 Share on other sites More sharing options...
dbo Posted June 23, 2008 Share Posted June 23, 2008 Sure thing. If you post your proposed database schema I'm sure we can help make sure you've got something that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.