Gazan Posted March 27, 2009 Share Posted March 27, 2009 Alright, here goes. I have a table that consists of numbers (123, 918, 328, 190) etc.. What i want to do is to get the average number from the database, and output them by php. How do i do that? if you could, please provide me with an example. I'd be very greatfull if you would Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted March 27, 2009 Share Posted March 27, 2009 if you're using mysql you can use the AVG function Quote Link to comment Share on other sites More sharing options...
Gazan Posted March 27, 2009 Author Share Posted March 27, 2009 I know of that, and not to sound rude, but i asked for an example so i could understand how to output it with php.. Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 27, 2009 Share Posted March 27, 2009 $query = "SELECT AVG(field) AS averageOfField FROM table WHERE..."; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo $row['averageOfField']; Quote Link to comment Share on other sites More sharing options...
Gazan Posted March 27, 2009 Author Share Posted March 27, 2009 Thanks alot! 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.