Jump to content

Archived

This topic is now archived and is closed to further replies.

Beauchy

Sorting Help Please

Recommended Posts

Cannot get it to sort according to date...

The problem is that I cannot change the file names but they are all in this format:

JAREPORT 05-05-06.txt
JAREPORT 05-07-06.txt
JAREPORT 06-01-06.txt

I want to display the files as links in a table according to month in descending order... eg 31, 30, 29, etc...

Everything works except the sorting...

How can I sort those files?

Thanks, Beauchy

Share this post


Link to post
Share on other sites
Put them in an array and use a custom sort function. For example, this sorts the middle part of the date in descending order
[code]
$files = array(
    'JAREPORT 05-05-06.txt',
    'JAREPORT 05-07-06.txt',
    'JAREPORT 06-01-06.txt'
);

usort ($files, 'monthsort');

// check results
echo '<pre>', print_r($files, true), '</pre>';

function monthsort($a, $b) {
   $ma = substr($a, 12, 2);
   $mb = substr($b, 12, 2);
   return -strcmp($ma, $mb);
}    [/code]

Share this post


Link to post
Share on other sites
Got it working!! [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Thank you very much! [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.