Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

1,2,3 instead of 1, 10, 2, 20 ??? 1

Status
Not open for further replies.

smashing

Programmer
Oct 15, 2002
170
US
I'm selecting data (mainly numbers) from a database and having it displayed in ascending order. I haven't chosen SORT BY because I want it in ascending order which is the default. I want it displayed properly like 1,2,3, 10, 20 instead of 1, 10, 2, 20. What's the trick ???

An idle mind is the Devil's workshop!!
 
The trick is to sort #'s instead of strings.

Either use sort by with the ASC DESC modifiers if you're database fields are already numeric, or if you're using PHP for the sorting just cast them into integers...

the second trick is to 0 pad the numbers, so you have
01,02,03

but then you may need 00004, 00003 if you're numbers are big enough.

And also PHP lets you write your own sorting functions to pass into many of the auto-sorts, so you could do it there....

good luck,
-Rob
 
Thanks. The second trick will do just fine for me.
 
why not try sprintf("%02.0f",$mctr) before printing it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top