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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   2449 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.