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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

sort first by 'Sort' ASC then by ''ID' DESC


Go to End


5 Posts   2228 Views

Avatar
DeklinKelly

Community Member, 197 Posts

13 May 2009 at 5:58am

I want to sort first by 'Sort' ASC then by ''ID' DESC

This code only sorts by ID:

 public function nextPager() {
  $where = "ParentID = ($this->ParentID + 0) AND Sort > ($this->Sort + 0 )";
  $pages = DataObject::get("SiteTree", $where, "Sort", "", 1);
  if($pages) {
   foreach($pages as $page) {
    return $page;
   }
  }
 }

Avatar
rbquirke

Community Member, 70 Posts

13 May 2009 at 10:33am

You want:

$pages = DataObject::get("SiteTree", $where, "Sort ASC, ID DESC", "", 1);

Avatar
DeklinKelly

Community Member, 197 Posts

13 May 2009 at 11:21am

rbquirke, your idea does not work. I get a database error.

Avatar
rbquirke

Community Member, 70 Posts

13 May 2009 at 12:31pm

What database error are you getting?

something about an ambiguous column?

Avatar
DeklinKelly

Community Member, 197 Posts

19 May 2009 at 10:41pm

Never mind, I had a type, thanks rbquirke.