Jump to content

order by help


keithschm

Recommended Posts

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

[!--quoteo(post=351394:date=Mar 3 2006, 02:14 PM:name=keithschm)--][div class=\'quotetop\']QUOTE(keithschm @ Mar 3 2006, 02:14 PM) [snapback]351394[/snapback][/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.
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.