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? 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? 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 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. 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. 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? 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. 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 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. Link to comment https://forums.phpfreaks.com/topic/111285-solved-getting-unique-votes/#findComment-571938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.