tux

12-02-2009, 08:10 PM

Need a bit of help guys.

I am building a rating system. To do this I am counting the rows from my table and getting the rating from each row using this......

$result = mysql_query("SELECT COUNT(*) FROM ratings WHERE imageID = '$imageID'");

$row = mysql_fetch_row($result);

$numrows = $row[0];

$query = "SELECT * FROM ratings WHERE imageID = '$imageID'";

$result = mysql_query($query);

$rating = mysql_fetch_array($result);

while($rating = mysql_fetch_array($result)){

$rating = $rating['rating'];

I need to add up the result of the while loop so I can then find the average rating by dividing the total by the number of rows. I think I need to use ARRAY_SUM but cant figure it out.

How do I total the result of the while loop?

Thanks all, Paul

I am building a rating system. To do this I am counting the rows from my table and getting the rating from each row using this......

$result = mysql_query("SELECT COUNT(*) FROM ratings WHERE imageID = '$imageID'");

$row = mysql_fetch_row($result);

$numrows = $row[0];

$query = "SELECT * FROM ratings WHERE imageID = '$imageID'";

$result = mysql_query($query);

$rating = mysql_fetch_array($result);

while($rating = mysql_fetch_array($result)){

$rating = $rating['rating'];

I need to add up the result of the while loop so I can then find the average rating by dividing the total by the number of rows. I think I need to use ARRAY_SUM but cant figure it out.

How do I total the result of the while loop?

Thanks all, Paul