I'm working on a system where users will submit comments about a topic, and that comment can be voted on with a thumb up or down. I've got a table for comments, each comment will have it's own unique ID, and I've got a table to track votes as well. I'm just wondering what would be the best way to accomplish this. I'm thinking using a boolean as the actual vote, so that a 1 is a thumb up and a 0 is a thumb down. Is there a better way though?
Also, when I'm displaying the votes on the page, should I run two separate queries to count the rows where the votes equal 0 and then 1, or is there a better way to do it so that I only have to do one query?
Edit: Just thought of this. Would a better way be to get rid of the votes table and add two new columns to the comments table: votes_up and votes_down, that way I can get the comment itself, plus the vote status all in one query. With this method, what would be the best way to order the comments, with higher rated comments coming first (the rating being the ratio of votes up to votes down.) Is there a way to do THAT wth MySQL of would it have to be done with PHP?