Aravinthan Posted January 31, 2010 Share Posted January 31, 2010 Hi guys, I have a little problem. So I want to order a table in a specific way. So I started building my code: $result = mysql_query("SELECT * FROM `teams` Order by ((`nhl_wins` *2) + `nhl_ot`) DESC",$link); while($row = mysql_fetch_array($result)) { if ($class == "class='odd'") { // this will rotate the value. $class = ""; }else{ $class = "class='odd'"; } // Moyenne Offensive $off = mysql_query("SELECT ROUND(AVG(`OFF`),2) AS `avgo` FROM teams JOIN players ON teams.id = players.team WHERE team='$row['team_name']'",$link); while($rowoff = mysql_fetch_array($off)) { $offe = "" .$rowoff['avgo']. ""; $offe = $offe / 10; } // Moyenne Defensive $def = mysql_query("SELECT ROUND(AVG(`DEF`),2) AS `avgd` FROM teams JOIN players ON teams.id = players.team WHERE team='$row['team_name']'",$link); while($rowoff = mysql_fetch_array($def)) { $defe = "" .$rowoff['avgf']. ""; $defe = $defe / 10; } // Moyenne Gardien $ga = mysql_query("SELECT ROUND(AVG(`OA`),2) AS `avgo` FROM teams JOIN players ON teams.id = players.team WHERE team='$row['team_name']' AND main_position ='1'",$link); while($rowoff = mysql_fetch_array($ga)) { $gar = "" .$rowoff['avgo']. ""; $gar = $gar / 10; } // Moyenne Generale $moyge = (round((($off + $def + $gar) / 3),2)) * 2; // Le reste $team = "" .$row['team_name']. ""; $gp = "" .$row['nhl_games_played']. ""; $wins = "" .$row['nhl_wins']. ""; $ot = "" .$row['nhl_ot']. ""; $loss = "" .$row['nhl_loss']. ""; $team = str_replace(" ", "", $team); $pts = (($wins * 2) + $ot) / 3.28; $winp = ((($ot * 0.5) + $wins) / $gp) * 100; $winp = round($winp, 2); $last10 = "" .$row['nhl_last10']. ""; $lwin = substr_count($last10, "W"); $lloss = substr_count($last10, "L"); $lot = substr_count($last10, "O"); $ltpo = (($wins * 2) + $ot) * 1.5; $total = $moyege + $pts + $ltpo; But its only after that I realised that it woudn't work. Because I want it to be ordered by the variable $total..... Can someone help me please? I want it to order by $total, but I dont know how... Thanks for your help, Ara Quote Link to comment https://forums.phpfreaks.com/topic/190456-order-by-help/ Share on other sites More sharing options...
RussellReal Posted January 31, 2010 Share Posted January 31, 2010 Two ways, do the math in the query, then just order by that math. OR make an array of the values, then have php sort it. if you choose path #2 asort Quote Link to comment https://forums.phpfreaks.com/topic/190456-order-by-help/#findComment-1004697 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.