Jump to content


Photo

MySQL ORDER BY


  • Please log in to reply
1 reply to this topic

#1 Andy Rixon

Andy Rixon

    Young Padawan

  • Members
  • Pip
  • 13 posts
  • Gender:Male
  • Location:Scotland, UK
  • Interests:PHP, MySQL CSS, HTML, My fiancee, My Daughter :D

Posted 21 September 2011 - 12:03 PM

Hello everyone, heres my problem.

I have an Xbox Live API and I offer people the ability to generate a gamer profile, on generation there gamertag gets added to a mysql database, and then when the profile link is visited, the api updates all t he information and the gamerscore is fetched and then an sql query is ran to update the gamerscore for that gamertag in the database, this is so I can create an Xbox Live leaderboard.

The problem is when it comes to displaying the results on a leaderboard page I use ORDER BY DESC to order the gamerscores (and gamertags) in order by the highest gamerscore, but it don't seem to work, it orders them, but in the wrong way, I have even tried ORDER BY gamerscore ASC, but it makes no difference, although I know it should be ORDER BY gamerscore DESC, heres the code;

<?php
// Query to select data from table
$query = "SELECT * FROM leaders ORDER BY gamerscore DESC";
$result = mysql_query($query); 
// Check if we are able to select data from table
if (!$result) {
	echo "Unable to fetch any gamers, there maybe a problem with the database.";
} else {
	while($row = mysql_fetch_array($result)):
?>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr>
	<td width="81%"><a href="profile.php?gamertag=<?php echo $row['gamertag']; ?>&format=html"><?php echo $row['gamertag']; ?></a></td>
	<td width="14%"><?php echo $row['gamerscore']; ?></td>
  </tr>
</table>
<?php endwhile ?>
<?php } ?>

Does anyone know where I'm going wrong with this.

Thank you in advance (and yes I know, its messy :D )

#2 Andy Rixon

Andy Rixon

    Young Padawan

  • Members
  • Pip
  • 13 posts
  • Gender:Male
  • Location:Scotland, UK
  • Interests:PHP, MySQL CSS, HTML, My fiancee, My Daughter :D

Posted 21 September 2011 - 02:03 PM

it was an issue with the structure, the gamerscore was varchar(255) when it should of been int(10).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users