I was just wondering what is the easiest way of calculating the total amount of votes from a mysql table. I have several rows, each one is an answer, and what I want to do is to add these into one integer...
What's the easiest way of doing this?
You don't give any clues as to you table structure, but assuming each record contains the value voted for for then
$query = select count(*) from mytable group by votefield;
will give a row for each value voted for and how many voted.
hth
but how do I echo out the result of the count(*) when it's done?
Try
$query = "select votefield, count(*) as total from mytable group by votefield"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "Votes cast for " . $row['votefield'] . " : " . $row['total']; }