Numeric Order

Posted on 2010-08-12
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 25

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 110

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 500 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Rhino Java Array in Javascript 1 39
Send email using HTML and PHP in separate file 5 41
Link Anchor Not working 9 51
geting data from the array list 6 18
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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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