alexguz79 Posted October 25, 2010 Share Posted October 25, 2010 Hey everybody, i'm building a website for the softball league i play in.... so far the website is pretty good... with all the stats and profiles.... i'm having a little problem with the ORDER of the leaders in the categories i have to calculate the result... for example... avg. is the result of the total hits divided by the total number of at bats... both numbers are coming from the database... the problem comes when i have to order the leaders from first to last... this is my php: $sql = "select profile_id, SUM(total_hits) AS hitstotal, SUM(ab) AS abtotal from batters WHERE year = '2010' GROUP BY profile_id"; $cons = mysql_query($sql); while ($result = mysql_fetch_array($cons)) { $sumaab = $resultad['abtotal']; $sumahits = $resultad['hitstotal']; $p_id = $resultad['profile_id']; $prom = round(($sumahits."") / ($sumaab.""),3); that gives me all the batting averages for the players. and here is my question: how can i order that $prom result from first to last? Link to comment https://forums.phpfreaks.com/topic/216784-help-with-order-a-result/ Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 Get mysql to do it, then order with it... http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_avg Link to comment https://forums.phpfreaks.com/topic/216784-help-with-order-a-result/#findComment-1126211 Share on other sites More sharing options...
alexguz79 Posted October 25, 2010 Author Share Posted October 25, 2010 Thaks for the tip... but AVG won't fix the problem 'cause i need to order the RESULT of two different columns divided. That value is not in MySql. Link to comment https://forums.phpfreaks.com/topic/216784-help-with-order-a-result/#findComment-1126217 Share on other sites More sharing options...
mentalist Posted October 25, 2010 Share Posted October 25, 2010 I remember running into this one, http://dev.mysql.com/doc/refman/5.0/en/create-function.html now my mysql is like kung fu (NOT!) Link to comment https://forums.phpfreaks.com/topic/216784-help-with-order-a-result/#findComment-1126222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.