(solved) Taking the best and most of columns.
Posted: Wed Apr 30, 2008 10:28 am
Hey, remember me?
Anyway, I'm stuck here on making a "world stats" page for my game. I want to tally up all the money in it, and display it as a variable. I could easily do this with a total pain-in-the-ass loop, but I'm quite certain there's a better way to do it with SQL.
The first is for all money, and the second for the highest-leveled monster in the game. However, I just can't figure out how to display them, I guess. :/ What to do?
EDIT: I figured it out. So odd, I guess I didn't expect it to work like this:
$allmoney = $allmoney['money']; should be " $allmoney = $allmoney['SUM(money)'];"
Code: Select all
$allmoney = mysql_query("SELECT SUM(money) FROM xx")or die(mysql_errror());
$allmoney = mysql_fetch_array($allmoney);
$allmoney = $allmoney['money'];
$hilevelmon = mysql_query("SELECT max(level) FROM xx LIMIT 0, 1");
$hilevelmon = mysql_fetch_array($hilevelmon);
$hilevelmon = $hilevelmon['level'];
EDIT: I figured it out. So odd, I guess I didn't expect it to work like this:
$allmoney = $allmoney['money']; should be " $allmoney = $allmoney['SUM(money)'];"