Simple Voting - Storing in Database
Posted: Tue Mar 02, 2010 7:46 pm
I'm working on implementing a voting system, similar to FMyLife or Texts From Last Night or those kinds of sites, with just a simple "thumbs up" or "thumbs down." I want to limit users to voting for something just one time, and I'm trying to figure out the best database structure to accomplish this.
I have a table of "places" and another table of "users." I'm thinking either I add another table of "votes", with a column for user and column for place, and with each vote I can check if there's already an entry for that user + that place in the votes table. Alternatively, I could add a column for "yes votes" and one for "no votes" on either the users or places table, and store the database ids of the places or users, respectively, that received the vote or performed the vote, in an imploded array.
For example, if users 3 and 7 voted yes for place 120, the "yes votes" column in the places table for place 120 would read "3,7". Or, the "yes votes" column in the users table for user 3 would read "120", as would the column for user 7.
Any other ideas?
Thanks.
I have a table of "places" and another table of "users." I'm thinking either I add another table of "votes", with a column for user and column for place, and with each vote I can check if there's already an entry for that user + that place in the votes table. Alternatively, I could add a column for "yes votes" and one for "no votes" on either the users or places table, and store the database ids of the places or users, respectively, that received the vote or performed the vote, in an imploded array.
For example, if users 3 and 7 voted yes for place 120, the "yes votes" column in the places table for place 120 would read "3,7". Or, the "yes votes" column in the users table for user 3 would read "120", as would the column for user 7.
Any other ideas?
Thanks.