Skip to main content

Forums

This topic contains 3 replies, has 0 voices, and was last updated by  brianatlarge 9 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28553

    brianatlarge
    Member

    I’m trying to display posts in reverse order from newest to oldest. I’ve got the following array filled with timestamped dates:

    I’m using array_reverse to try to flip the order, but it doesn’t seem to work:

    Code:
    < ?php print_r($dateArr); array_reverse($dateArr); print_r($dateArr); ?>
    Code:
    Array
    (
    [0] => 2010-03-27 15:43:31
    [1] => 2010-03-27 20:28:50
    [2] => 2010-03-27 20:52:28
    )
    Array
    (
    [0] => 2010-03-27 15:43:31
    [1] => 2010-03-27 20:28:50
    [2] => 2010-03-27 20:52:28
    )

    Am I not doing this right?

    #73103

    Argeaux
    Participant

    How about this:

    Code:
    < ?php print_r($dateArr); $dateArr = array_reverse($dateArr); print_r($dateArr); ?>
    #73104

    brianatlarge
    Member

    That was it. Thanks.

    #73367

    Irrorate
    Member

    I realise this was solved already, but wouldn’t it have been more efficient to sort the replies when executing the query?

    Code:
    SELECT * FROM posts ORDER BY timestamp DESC

    That will select all the posts and order by the most recent timestamp (i.e. newest to oldest)?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star