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 Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.