Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Get the last 8 items by date and display them in reverse order

Go to End

2 Posts   944 Views


Community Member, 30 Posts

2 October 2013 at 10:47am

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


Forum Moderator, 5523 Posts

4 October 2013 at 7:59pm

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