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 Link to comment https://forums.phpfreaks.com/topic/151360-get-average-of-numbers-from-database/ 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 Link to comment https://forums.phpfreaks.com/topic/151360-get-average-of-numbers-from-database/#findComment-794988 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.. Link to comment https://forums.phpfreaks.com/topic/151360-get-average-of-numbers-from-database/#findComment-794989 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']; Link to comment https://forums.phpfreaks.com/topic/151360-get-average-of-numbers-from-database/#findComment-794990 Share on other sites More sharing options...
Gazan Posted March 27, 2009 Author Share Posted March 27, 2009 Thanks alot! Link to comment https://forums.phpfreaks.com/topic/151360-get-average-of-numbers-from-database/#findComment-794996 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.