Jump to content


Photo

ORDER BY numbers in mysql query *SOLVED*


  • Please log in to reply
4 replies to this topic

#1 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 14 June 2006 - 09:24 AM

I have the following query

$r2 = mysql_query("SELECT * FROM album_tracks WHERE at_album = '$aId' ORDER BY at_order") or die(mysql_error());

at_order is a number, and there are 10 rows. When the results are listed, they come in the following order: 1, 10, 2, 3, 4 etc....

How do I get the numbers to list properly? ie: 1, 2, 3, 4 ..... 10
If you're not part of the solution, you're part of the precipitate

#2 phpvolution

phpvolution
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 14 June 2006 - 09:34 AM

$r2 = mysql_query("SELECT * FROM album_tracks WHERE at_album = '$aId' ORDER BY at_order ASC") or die(mysql_error());

ASC or DESC, I forget which way each goes =P

#3 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 14 June 2006 - 09:39 AM

Thanks for the help but 10 is still in the wrong place :(
If you're not part of the solution, you're part of the precipitate

#4 phpvolution

phpvolution
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 14 June 2006 - 09:46 AM

Check your DB structure, those numbers could be stored as characters or text, that's usually the case because it looks like it's sorting that way. Make sure they are stored as integers.

#5 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 14 June 2006 - 09:52 AM

Sweet, that did the trick.

Cheers :)
If you're not part of the solution, you're part of the precipitate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users