jcbarr Posted December 6, 2006 Share Posted December 6, 2006 What I want to do is query the database for several rows. For each row I want to add two columns together, get the sum of those two columns then order them DESC and print them in that order in a while loop.For example here is how one line would look if I were to run the query for just one row.[code]$query=mysql_query("SELECT * FROM rosters WHERE PID='$pid'");$player=mysql_fetch_assoc($query);$value=$player['ch']+$player['ph'];echo $player['firstname'] . " " . $player['lastname'] . " " . $player['ch'] . " " . $player['ph'] . " " . $value;[/code]So the question is how do I code a loop that does that for every row that meets a certain criteria such as Team='$team' that will order the output by the value? Link to comment https://forums.phpfreaks.com/topic/29741-order-by-the-sum-of-two-columns/ Share on other sites More sharing options...
trq Posted December 6, 2006 Share Posted December 6, 2006 [code]SELECT fld1+fld2 AS total ORDER BY total DESC;[/code] Link to comment https://forums.phpfreaks.com/topic/29741-order-by-the-sum-of-two-columns/#findComment-136544 Share on other sites More sharing options...
jcbarr Posted December 6, 2006 Author Share Posted December 6, 2006 Awesome, I knew it was something easy like that. Link to comment https://forums.phpfreaks.com/topic/29741-order-by-the-sum-of-two-columns/#findComment-136545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.