Phpfr3ak Posted September 23, 2010 Share Posted September 23, 2010 Hi any clues as to why this doesn't work, probably real simple having a slow day. <?php $ReportType = mysql_real_escape_string($_GET['ReportType']); $sql = "SELECT id, username, score, class, Banned FROM users WHERE is_active = 1 ORDER BY $ReportType DESC LIMIT 25"; $query = mysql_query($sql) or die(mysql_error()); $i=0; while($users = mysql_fetch_array($query)) { $i++; ?> Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/ Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 What's it doing? What error message? What should it be doing? Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114686 Share on other sites More sharing options...
Pikachu2000 Posted September 23, 2010 Share Posted September 23, 2010 What about it doesn't work, and how can you tell, since it doesn't generate any output? Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114689 Share on other sites More sharing options...
Phpfr3ak Posted September 23, 2010 Author Share Posted September 23, 2010 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DESC LIMIT 25' at line 1 If i sort by score it works... and shows the top 50 players, thats the section i changed. I'm wanting to vary it by $ReportType Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114699 Share on other sites More sharing options...
Pikachu2000 Posted September 23, 2010 Share Posted September 23, 2010 The $ReportType variable needs to contain a valid field name from your table. It would seem that currently it does not. Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114702 Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 Agreeing to what Pikachu2000 said. But beyond that, what is $ReportType returning? (What kind of value?) Maybe we can help you find a way to do the sort you want. Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114706 Share on other sites More sharing options...
rwwd Posted September 23, 2010 Share Posted September 23, 2010 <?php $ReportType = mysql_real_escape_string($_GET['ReportType']); echo $sql = "SELECT `id`, `username`, `score`, `class`, `Banned` FROM `users` WHERE `is_active` = 1 ORDER BY `".$ReportType."` DESC LIMIT 25"; $query = mysql_query($sql, $connectionHandle) or die(mysql_error());//if already reference, leave as it was $i=0; while($users = mysql_fetch_array($query)) { $i++; //Hopefully your breaking out of php here to do direct html... ?> You really need to echo the sql string to screen to see how it's populated too, run that, see what happens... Rw Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114710 Share on other sites More sharing options...
Phpfr3ak Posted September 23, 2010 Author Share Posted September 23, 2010 Sorry it actually does work upon closer inspection... well ranks the players as ordered in each area. The only issue i have now is with the whole <?php echo $users['score'] ?> area as how would i make it echo the $ReportType, instead of score the $reporttype is already defined. Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114716 Share on other sites More sharing options...
rwwd Posted September 23, 2010 Share Posted September 23, 2010 <?php echo $users['score']; ?> 1 Added char there, other than that, not sure what your meaning.... Rw Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114718 Share on other sites More sharing options...
Phpfr3ak Posted September 23, 2010 Author Share Posted September 23, 2010 Sorry its rather difficult for me to explain. I'll try the best i can; cash_Stole currently <?php $sql = "SELECT id, username, score, class, Banned FROM users WHERE is_active = 1 ORDER BY $ReportType DESC LIMIT 25"; $query = mysql_query($sql) or die(mysql_error()); $i=0; while($users = mysql_fetch_array($query)) { $i++; ?> successfully ranks the players in the database in order of who has most of what. e.g http://urlhere.com//top.php?ReportType=cash_Stolen This will currently who has the highest cash_stolen colum in the database. Id like to then echo what the actual number is... if this makes sense but the report types vary, yet are defined e.g e.g http://urlhere.com//top.php?ReportType=cash_Stolen orders by most cash stolen e.g http://urlhere.com//top.php?ReportType=score orders by score This currently works with the actual ranking in the php code i showed above. but id like to change <?php echo $users['score']; ?> to something that would echo the actual users information from the database for that area using $ReportType. If this makes sense to you. Link to comment https://forums.phpfreaks.com/topic/214226-having-a-retarded-moment/#findComment-1114733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.