zackcez Posted July 3, 2008 Share Posted July 3, 2008 I keep getting an error when I try this so...Here's my current codes: $total = Attackxp + Woodcuttingxp + Defencexp + Strengthxp + Hitpointsxp + Rangexp + Prayerxp + Magicxp + Cookingxp + Fletchingxp + Fishingxp + Firemakingxp + Craftingxp + Smithingxp + Miningxp + Herblorexp + Agilityxp + Thievingxp + Slayerxp + Farmingxp + Runecraftingxp; $result = mysql_query("SELECT * FROM user ORDER BY $total DESC LIMIT 25"); If anyone knows the correct way to do this...please post here ;o BTW, Attackxp, ect are all rows in the user table Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/ Share on other sites More sharing options...
discomatt Posted July 3, 2008 Share Posted July 3, 2008 I don't see any errors. Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581262 Share on other sites More sharing options...
zackcez Posted July 3, 2008 Author Share Posted July 3, 2008 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [path]/modules/test.php on line 99 Here's the fetch array...but I already know the problem isn't in that: while($row = mysql_fetch_array($result)){ $i++; echo "<tr align=\"center\"><td class=\"alt1\" nowrap=\"nowrap\" width=\"5%\" align=\"left\">$i</td><td class=\"alt1\" nowrap=\"nowrap\" width=\"15%\" align=\"left\">" . $row['username'] . "</td> <td class=\"alt1\" nowrap=\"nowrap\" width=\"10%\" align=\"left\">" . $row[$skill_lvl] . "$total</td><td class=\"alt1\" nowrap=\"nowrap\" width=\"15%\" align=\"left\">" . $row[$stat] . "$totalxp</td></tr>"; } Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581280 Share on other sites More sharing options...
teynon Posted July 3, 2008 Share Posted July 3, 2008 Is there any data in your database? Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581282 Share on other sites More sharing options...
zackcez Posted July 3, 2008 Author Share Posted July 3, 2008 Yeah... Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581283 Share on other sites More sharing options...
AndyB Posted July 3, 2008 Share Posted July 3, 2008 The syntax for your query ought to be SELECT from tablename ORDER by fieldname DESC LIMIT 25. If the value of $total happened to be 250, do you actually a database field named 250? I doubt it. And that's why you get an error. Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581350 Share on other sites More sharing options...
zackcez Posted July 3, 2008 Author Share Posted July 3, 2008 Ah, well I seriously can't think of how to do it then :s Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581354 Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 The syntax for your query ought to be SELECT from tablename ORDER by fieldname DESC LIMIT 25. If the value of $total happened to be 250, do you actually a database field named 250? I doubt it. And that's why you get an error. Not so, he is just missing string quotes around the field names, MySQL can do the summation work for him. $total = "Attackxp + Woodcuttingxp + Defencexp + Strengthxp + Hitpointsxp + Rangexp + Prayerxp + Magicxp + Cookingxp + Fletchingxp + Fishingxp + Firemakingxp + Craftingxp + Smithingxp + Miningxp + Herblorexp + Agilityxp + Thievingxp + Slayerxp + Farmingxp + Runecraftingxp"; $q = "SELECT * FROM user ORDER BY $total DESC LIMIT 25"; echo $q; $result = mysql_query($q); The reason I put the query into its own variable $q and made it echo is so you can see what the actual query you're running is. You can then plug that into a DB front-end (like PhpMyAdmin) to see what the result set is if need be. Also, you should check out http://php.net/mysql_error Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581361 Share on other sites More sharing options...
zackcez Posted July 3, 2008 Author Share Posted July 3, 2008 Still isn't working :s Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581372 Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 If you want further help, you'll need to specify what you mean by "still isn't working" - how much debugging have you done? Link to comment https://forums.phpfreaks.com/topic/113142-solved-mysql-order-by/#findComment-581378 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.