# Numeric Order

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?
numberingORder.png
LVL 1
###### Who is Participating?

Commented:
try using ksort() it will sort the array by key value.

``````if(is_array(\$R)):
ksort(\$R);
foreach (\$R as \$key=>\$val):
``````
0

Systems architectCommented:
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.

0

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

http://uk.php.net/manual/en/function.natsort.php

This treats numbers as humans would.
0

Commented:
Hi,

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
0

Commented:
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.
0

Commented:
Please post the code segment that retrieves the data.
0

PluritechnicianCommented:
0

Author Commented:
HI All

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

\$i=0;
\$R=getRequests();
if(is_array(\$R)):
foreach (\$R as \$key=>\$val):
\$bgc=getBGC(\$i);

?>
<tr bgcolor="<?=getBGC(\$i)?>">
<td><a href="#" onclick="getRequest('<?=\$R[\$key]['R_NUMBER']?>');return false;"><?=\$key?></a></td>
<td><?=formatDate(\$R[\$key]['R_DATE_SUBMITTED'],'y-m-d','m/d/y')?></td>
<td><?=translateField(\$R[\$key]['R_STATUS'])?></td>
</tr>

<?\$i++;endforeach;endif;?>
</table>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.