Link to home
Start Free TrialLog in
Avatar of justmelat
justmelat

asked on

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
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

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.

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.
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
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.
Please post the code segment that retrieves the data.
Avatar of justmelat
justmelat

ASKER

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><?=$R[$key]['ANSWER']['Q_6']?></td>
<td><?=$R[$key]['ANSWER']['Q_7']?></td>
<td><?=formatDate($R[$key]['R_DATE_SUBMITTED'],'y-m-d','m/d/y')?></td>
<td><?=$R[$key]['ANSWER']['Q_5']?></td>
<td><?=translateField($R[$key]['R_STATUS'])?></td>
</tr>

<?$i++;endforeach;endif;?>
</table>
ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial