Web Hosting Talk







View Full Version : Ordering mysql data AFTER extraction


GA PunkFreak
11-02-2005, 04:37 PM
Hello,

I am wondering if any of you have any ideas of how I can accomplish this:

I have a mysql table with five rows of each team, with columns "Wins" and "Losses" (just the number of wins and losses the team currently has).

I want to be able to select all the teams, then find the Win percentage in PHP (simply Wins divided by Wins + Losses), then order the rows based on that percentage.

Thanks,
-Phil

uncleThirteen
11-02-2005, 05:07 PM
I you are only trying to order by winning percent (I also order by games back, for example) you could try doing it in your query like so:

select *, games_won/(games_lost + games_won) as winning_percent from games order by winning_percent

if you are doing anything else, use array functions.

hiryuu
11-02-2005, 07:10 PM
Note that you can also "ORDER BY games_won/(games_lost + games_won)" directly, although, in this case, you probably want that information returned anyway.