View Full Version : Display average of database entries?

11-24-2009, 07:25 PM
How can I display a records average value? For example I am working on a page where users can rate the material from one to ten. The submitted data goes into a database. Now how can I take all of those values and display the average on a results page?

11-28-2009, 06:11 PM
I found a good tutorial on how to do this at this address... http://www.plus2net.com/php_tutorial/rating.php

12-12-2009, 12:11 AM
My post here might help.


12-16-2009, 06:59 PM
Got it working, now any idea how to limit the rating to only two character's after the decimal so instead of getting ratings that look like 1.88888888 it shows up as just 1.88 ?

12-17-2009, 12:31 AM
heres a snippet that will help
echo "The number = ". $number; // will display 25.66745
echo "<br>Rounded value of the number = ".round($number,2); // will display 25.67

12-17-2009, 05:57 AM
or when you echo the result of this......


$value = 1.88888888;

echo number_format($value, 2, ".", ",");


..... you will get 1.89