abhikerl Posted June 9, 2008 Share Posted June 9, 2008 hi, can anyone tell me how to calculate the average of data retrieves from a database. The situation is I have a table "number" which consist of several data like "2,5,4,8,6...." I want to calculate the average and display it on the browser. thanks in advance for your help. http://www.islandinfo.mu Link to comment https://forums.phpfreaks.com/topic/109368-calculate-average-from-rows-in-a-database/ Share on other sites More sharing options...
GingerRobot Posted June 9, 2008 Share Posted June 9, 2008 Use MySQL's average function: $result = mysql_query("SELECT AVG(yourfield) FROM yourtable") or die(mysql_error()); $average = mysql_result($result,0); echo 'Average: '.$average; Link to comment https://forums.phpfreaks.com/topic/109368-calculate-average-from-rows-in-a-database/#findComment-560965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.