TEENFRONT Posted November 15, 2008 Share Posted November 15, 2008 Hey il jump straight in, im confused with a way to order some results... heres the stuff.. $result = mysql_query("SELECT * FROM teams"); OK so that selects everything from the table teams (obiously lol) while($row = mysql_fetch_array($result)) { $played = $row['played']; $won = $row['won'] $teamname = $row['teamname']; $rating = round($won /($played /100)); // works out rating out of 100 from games played to games won. echo "$teamname - $rating"; // EG output: "Team1 - 70" } ok so that runs the while loops, and gets the team info, and applies a rating for them..but you know what im gunna ask lol, i want to order the results by the rating value..but the rating value isnt found untill after the query, so, how do i add the rating math to an order by value? so right now it outputs this. Team1 - 70 Team2 - 60 Team3 - 88 Team4 -75 i obviously want it like this Team3 - 88 Team4 - 75 Team1 - 70 Team2 - 60 Id really love any help, iv been up for a few hours....now i have a headache lolol. Quote Link to comment https://forums.phpfreaks.com/topic/132822-complicated-ordering/ Share on other sites More sharing options...
Mchl Posted November 15, 2008 Share Posted November 15, 2008 SELECT *, (won / (played / 100)) AS rating FROM teams ORDER BY rating Quote Link to comment https://forums.phpfreaks.com/topic/132822-complicated-ordering/#findComment-690752 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.