Jump to:

3377 Posts in 1001 Topics by 714 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Get the last 8 items by date and display them in reverse order

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 230 Views
  • Mauro74
    Avatar
    Community Member
    30 Posts

    Get the last 8 items by date and display them in reverse order Link to this post

    I'm a beginner in PHP and Silverstripe so I apologise if the question has a very simple answer.
    I'm trying to get the last 8 items by date from a list of gigs and display them in reverse (ascending) order. here's my code:

    //my php function
    function Tour() {
    if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
    $SQL_start = (int)$_GET['start'];
    $doSet = DataObject::get(
    $callerClass = "GigDetail",
    $filter = "",
    $sort = "Date ASC",
    $join = "",
    $limit = "{$SQL_start},8"
    );

    return $doSet ? $doSet : false;
    }

    //my ss file
    <% control Tour %>
    <p>$Place - $Date.Nice - $Address <a href="$Link">more &raquo;</a></p>
    <% end_control %>

    This will show them in reverse order but from the bottom of the list. while I want to get the latest 8 gigs by date and display them in reverse order. Does it have anyting to do with $_GET['start'] ?

    Thanks in advance
    Mauro

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Get the last 8 items by date and display them in reverse order Link to this post

    Wouldn't you want to use $sort = "Date DESC", to get highest to lowest rather than ASC?

    230 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.