counting up yes votes?
Date: 08/20/07
(WebDesign) Keywords: php, mysql, database, sql
I have a mySQL database, and one of the tables is used as the backend for a ratings system in which people can rate images on a scale of 1-5. In it, I have columns for the following data: id (a primary key field), userid (their phpBB userid), total votes cast, and then a column for every item in the rating system, just as a y/n toggle to check whether or not a person has rated that item. Actual scores are stored elsewhere.
My problem is fairly simple: I need to clear some of the ratings, because the images are going to change. How can I count up the total number of 'y' in a row in my database in order to update the total votes to reflect that some votes have been reset? Each row represents one user's votes, so it might say that user 1 has voted on images 1, 3 and 5, but not 2 and 4. I want to be able to find out that user 1 has voted 3 times. mysql_num_rows, of course, just returns 1, and I think mysql_num_cols/columns doesn't exist. Right now, the system simply works that every time a user rates something, the total vote is incremented by 1. Does anyone know what I need to do?
Source: http://community.livejournal.com/webdesign/1298510.html