Numeric Order

Posted on 2010-08-12
Medium Priority
Last Modified: 2012-05-10
View the attached shot

How do I force the number ordering from1, 2, 3,4,5, 6 and so on instead of 1, 100, 101, 2, 200, 201, etc in my php application?
Question by:justmelat
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 63

Expert Comment

ID: 33421276
From the bubble "Click to sort" I read that you have some library function doing the sorting on browser side.
Show the html page source so we can see what you are using there.

LVL 16

Expert Comment

ID: 33421361
If you have the numbers in an array, you can use a PHP function such as natsort:


This treats numbers as humans would.
LVL 26

Expert Comment

ID: 33421368

Some suggestion:

for the date I recommand using yyyy_mm_dd format
for other kind of number you can add an extra 0 in front of the number
001, 010 etc
Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

LVL 111

Expert Comment

by:Ray Paseur
ID: 33422795
If the column named "Number" is actually a number, the query can use ORDER BY to get these in the right sequence.  Look at the data type to see if it is INT or DECIMAL or some other numeric variant.  I think INT is probably what you want.

If the column is not a number (like VARCHAR) you have a goofy data base design.  But you can cast the value to an integer by adding zero to it during the SELECT statement.
LVL 19

Expert Comment

ID: 33423666
Please post the code segment that retrieves the data.
LVL 82

Expert Comment

ID: 33424993

Author Comment

ID: 33486452
HI All

this is the code that spits out my list of jobs:

foreach ($R as $key=>$val):

<tr bgcolor="<?=getBGC($i)?>">
<td><a href="#" onclick="getRequest('<?=$R[$key]['R_NUMBER']?>');return false;"><?=$key?></a></td>

LVL 19

Accepted Solution

Michael701 earned 2000 total points
ID: 33486686
try using ksort() it will sort the array by key value.

foreach ($R as $key=>$val):

Open in new window


Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question