effective retrieve for a voting system in PHP

Posted by Adnan on Stack Overflow See other posts from Stack Overflow or by Adnan
Published on 2010-04-11T09:48:03Z Indexed on 2010/04/11 9:53 UTC
Read the original article Hit count: 414

Filed under:
|

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

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about best-practices