I am working on a PHP application that has several objects that can be commented on. Each comment can be voted, while users can give it +1 or -1 (for example, Digg or Reddit). Right now, I plan to have a βvotesβ table that has user_id and their voting information, which seems to work fine.
The fact is that each object has hundreds of comments, which are stored in a separate comment table. After I upload the comments, I have to count the votes and then individually check each vote against the user to make sure that they can vote only once. This works, but just seems really intense in the database - a lot of comments-only queries.
Is there an easier way to do this, which is less database intensity? Is my current database structure the best way?
To clarify the current database structure:
Comment table:
- user_id
- object_id
- total_votes
Voting table:
Final goal:
- Allow the user to vote only once for each comment with the least number of MySQL queries (each object has several comments)
comments php mysql voting
mdolon
source share