Reputation: 662
I want to get the results of all the rows with a pending status and after that display the rest that dont have pending . I cant get the syntax right to order the data this way . I want all the pending value rows and then all the other non-pending rows.
$this->Paginator->settings = array(
// 'conditions' => array('request_status' => 'pending') ,
'order' => array('request_status' => 'pending','request_date'=> 'desc'),
'limit' => 5 );
Upvotes: 0
Views: 179
Reputation: 385
You can sort on multiple columns, and you can sort different columns in different directions. For example, to sort by type of request_date in descending order, then by request_status within request_type in descending order ('youngest' request_date first), use the following query:
mysql> SELECT * FROM pet
-> ORDER BY request_status, request_date DESC;
CakePHP:
'order' => array('request_status, request_date DESC');
The DESC keyword applies only to the column name immediately preceding it (request_date); it does not affect the request_status column sort order yet will group them. In other words, above sql query will group request_status fields ordered by their request_date fields.
Another useful link for paginator sorting it's this one.
Upvotes: 0
Reputation: 1533
'request_status' => 'pending'
should be either 'request_status' => 'asc'
or 'request_status' => 'desc'
depending on preference. It doesn't belong in the order conditions as you have specified as its part of a WHERE clause and not an ORDER BY
EDIT:
IF its a standard display that you're looking to render, then use the model rather than pagination settings. I had difficulty with them before. So in the model you would define an order variable
public $order = array("request_status" => "ASC");
or
public $order = array("request_status" => "DESC");
In the controller for a view, it would be a case of calling the standard
$this->set('mydata' , $this->Paginator->paginate);
Upvotes: 1