effective retrieve for a voting system in PHP and MySQL
- by Adnan
Hello,
I have a system where registered users can vote up/vote down comment for a picture. Something very similar to SO's voting system.
I store the votes in a table with values as such;
vote_id | vote_comment_id | vote_user_id | vote_date | vote_type
Now I have few a question concerned the speed and efficiency for the following;
PROB: Once a user opens the picture page with comments I need, if that user has already voted UP/DOWN a comment to show it like; "you voted up" or "you voted down" next to the comment (in SO it the vote image is highlighted)
MY POSSIBLE SOL: Right now when I open a picture page for each comment I loop thru, I loop thru my table of votes as well and check if a user has voted and show the status (I compare the vote_user_id with the user's session).
How efficient is this? Anyone have a better approach to tackle this kind of problem?