Jump to content

[SOLVED] Problem with mysql ORDER BY


skatermike21988

Recommended Posts

Hello everyone,

 

I am creating a script that when a user signs up they have the option to input their xbox live gamertag.

 

With the gamertag I pull their gamercard to display on their profile.

 

Well I am trying to make a leaderboard that displays leaders by their gamerscore.

 

So.. I have made a cron job that checks and gathers the required info and inserts it into the mysql which works fine. At the very end of the cron job I have it update their rank position which is where I am having the problem.

 

The code looks like this for the update:

 

$getrank = mysql_query("SELECT * FROM xboxleaderboard ORDER BY `gamerscore` DESC;");
$rank=0;
while($info = mysql_fetch_array( $getrank ))
{

$userid = $info['userid'];
$rank=$rank+1;
$updaterank = "UPDATE `xboxleaderboard` SET `rank` = '$rank' WHERE userid = '$userid'";
$updaterankresult = mysql_query($updaterank);

}

 

the $rank adds fine but mysql is not pulling the data right

 

my database looks like this:

 

--------------------------------

gamerscore| gamertag      | rank

--------------------------------

450          |skatermike219  | 1

21922      |NeutralX2     |  3

36607      |Gemini711     |  2

---------------------------------

 

That's what it looks like after the script runs

 

as you can see skatermike219 should not be ranked number 1

and of course Gemini711 should not be ranked number 2

 

it should be:

--------------------------------

gamerscore| gamertag      | rank

--------------------------------

450          |skatermike219  | 3

21922      |NeutralX2     |  2

36607      |Gemini711     |  1

--------------------------------

 

Any help appreciated this is really starting to bug me.

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/116389-solved-problem-with-mysql-order-by/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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