Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/11743-sorting-help-please/
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]
Link to comment
https://forums.phpfreaks.com/topic/11743-sorting-help-please/#findComment-44484
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\" /]
Link to comment
https://forums.phpfreaks.com/topic/11743-sorting-help-please/#findComment-44513
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.