Jump to content

Having a retarded moment


Phpfr3ak

Recommended Posts

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.