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