Solved

Numeric Order

Posted on 2010-08-12
8
269 Views
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?
numberingORder.png
0
Comment
Question by:justmelat
8 Comments
 
LVL 63

Expert Comment

by:Zvonko
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.

0
 
LVL 16

Expert Comment

by:HackneyCab
ID: 33421361
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
 
LVL 24

Expert Comment

by:lenamtl
ID: 33421368
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
 
LVL 108

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.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 19

Expert Comment

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

Expert Comment

by:leakim971
ID: 33424993
0
 
LVL 1

Author Comment

by:justmelat
ID: 33486452
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>
0
 
LVL 19

Accepted Solution

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




if(is_array($R)):

ksort($R);

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

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 Searchbox Branding 11 45
Update from TABLE-A to TABLE-B 5 39
Move wordpress site 3 24
Why my select dropdown does not work? 8 27
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now