Jump to content

Archived

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

keithschm

order by help

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.