Forum Moderators: open
1. I could have a table with 2 fields. One has the picture ID. The other has a list of everyone who has rated the picture seperated by commas. The server would parse that list and dump all the names into an array that can be checked.
2. Have a table with a field for the user ID. Also have a field listing all pictures reviewed seperated by commas. Again, parse and check that list.
I suspect there is a better way to do this but I can't think of one at the moment. Any suggestions?
Users Table
--------
ID
UsersToPictures Table
---------
UserID
PictureID
When you want to check if the user has already voted, run this sort of query:
SELECT TOP 1 ID FROM Pictures WHERE ID NOT IN (SELECT PictureID FROM UsersToPictures WHERE UserID = TheUserIDHere AND PictureID = ThePictureIDHere)
The record that is returned will be the ID of a picture that is eligible to be voted on by the User (they have not already voted on it). If there is no record returned, they have voted on all the pictures. Just make sure you have proper indexes on your columns.
SELECT TOP 1 ID FROM Pictures WHERE ID NOT IN (SELECT PictureID FROM UsersToPictures WHERE UserID = TheUserIDHere AND PictureID = ThePictureIDHere)
OK, I get the first select statement gets the first item that does not show listed in the UsersToPictures table for a particular user. The 2nd part looks like it produces a list of all the pictures that the user has viewed so far. The part I'm not sure about is the end of the 2nd statement. Why do you need "AND PictureID = ThePictureIDHere"? Also, what exactly is ThePictureIDHere?
Thanks so far for the help!