Page 1 of 1

Mysql Problem

Posted: Wed Mar 02, 2005 5:56 pm
by cbrian
Well, I'm working on a text-based game, and for a top ten list, I need to get the players with the most gold. Using the following code, I want to add the player's bank gold and gold together. But it ends up with this:

1 - cbrian (4,364,664,514g)
2 - ikki (8,581,934,390g)
3 - Ecko (8,581,935,340g)
... and the rest is fine.

Code:

Code: Select all

$query = mysql_query("SELECT * FROM users ORDER BY 'bank_gold'+'gold' DESC");

Posted: Wed Mar 02, 2005 6:20 pm
by s.dot
YOu could set it as a variable before you do the query

Code: Select all

$totalgold = $bank_gold + $gold;
And use $totalgold in your query.

Posted: Wed Mar 02, 2005 6:29 pm
by cbrian
That's what I thought at first, but this is in a loop, so it changes. I'm not sure if it would work.

Posted: Wed Mar 02, 2005 6:36 pm
by smpdawg
Try this.

Code: Select all

$query = mysql_query("SELECT *, (bank_gold + gold) AS total_gold FROM users ORDER BY total_gold DESC");

Posted: Wed Mar 02, 2005 6:40 pm
by cbrian
Ahhh, that worked great. Thanks a lot!