Jump to content


Photo

order by help


  • Please log in to reply
2 replies to this topic

#1 keithschm

keithschm
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 03 March 2006 - 07:14 PM

ok I am quering a table that has a number of fields. one of the fields is "rank". each entry has a number in the rank field 1 through 24. I am sorting by that field. "ORDER BY rank"

but instead of ordering like 1,2,3,4, etc it orders it by 1,10,11,12,13.....2,20,21,22,.....3,4,5,6,7,8,9

if I sort the table trough phpmyadmin it sorts the same way as well, What am I doing wrong. Do I have to change the type of that field. it is currently a text field.

thanks
NEED HELP

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 03 March 2006 - 07:20 PM

[!--quoteo(post=351394:date=Mar 3 2006, 02:14 PM:name=keithschm)--][div class=\'quotetop\']QUOTE(keithschm @ Mar 3 2006, 02:14 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]Do I have to change the type of that field. it is currently a text field.

thanks
[/quote]

welcome to the forums! i hope you get lots of help here!

to get it to sort numerically, you have to have a numeric field, so, yes, you'd do better to have it as an INT field in the database. it is sorting alphabetically since it's a string, and alphabetically, the numbers are taken character by character and matched, not as a whole.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 keithschm

keithschm
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 03 March 2006 - 07:35 PM

wow thanks, that was easy. Thanks for the help


I just donated $20 to the cause.


NEED HELP




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users