Im currently creating a voting module for my website, and i have to check if the user voted already, it would just select * from the vote logs, my script inserts a new record for each vote, so say you vote on site 1 its a different record, then say if you voted for site 2.
The columns are site, and the username. I wan’t to be able to check if they voted on all sites based on their username in one php mysql query SELECT * FROM TABLE_NAME
And then sort through the information that way, but i can’t wrap my head around it….
Any help’s appreciated as always!
Here is how I would set it up:
Users table:
Sites table:
Votes table:
When a user casts a vote:
To see what sites a user has voted on:
To see what sites a user has NOT voted on (if no rows are returned, then the user has voted on every site):
I like this solution, because then you can display which sites the user has not voted on.
A couple final notes: (1) Never, EVER use “SELECT * FROM table” in a production setting; this is terrible performance. Always select the only the rows you need. And (2) be sure to quote the user input on your queries to avoid SQL injection attacks.