Jump to content

Order by the sum of two columns


jcbarr

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.