So I have a row of "votes" (1 to 5) and I want to display the average rating.
In my database each row has a vote So
3 5 2 5 2 3
How do I display the average of these votes? Thanks -Arron
sum / total = average, surely you were taught that at school? 😉
AVG() is pretty much a standard database function too.
Hows the syntax for AVG() ?
<?php $SQLx = "SELECT AVG() from VOTES"; $resultx = mysql_query( $SQLx ); $rowx = mysql_fetch_array( $resultx ); echo $rowx[RATING]; ?>
Sure that wrong, how to use AVG() ?
It could be as simple as:
$query = "SELECT AVG(RATING) FROM VOTES"; $result = mysql_query($query); echo mysql_result($result, 0);
Once again, thanks laserlight!