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.

General Questions

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

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

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


Reply

5 Posts   1668 Views

Avatar
DeklinKelly

13 May 2009 at 5:58am Community Member, 197 Posts

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

13 May 2009 at 10:33am Community Member, 70 Posts

You want:

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

Avatar
DeklinKelly

13 May 2009 at 11:21am Community Member, 197 Posts

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

Avatar
rbquirke

13 May 2009 at 12:31pm Community Member, 70 Posts

What database error are you getting?

something about an ambiguous column?

Avatar
DeklinKelly

19 May 2009 at 10:41pm Community Member, 197 Posts

Never mind, I had a type, thanks rbquirke.