How do I change the find query order option so the username comes first for the result?
$params = array(
'fields' => array('User.firstname', 'User.lastname', 'User.username', 'User.lat', 'User.lng', 'User.thumbnail_image', 'User.status', '6371 * ACos( Cos( RADIANS( User.lat ) ) * Cos( RADIANS( '.$lat.' ) ) * Cos( RADIANS( '.$lng.' ) - RADIANS( User.lng ) ) + Sin( RADIANS( User.lat ) ) * Sin( RADIANS( '.$lat.' ) ) ) as distance'),
'limit' => 15,
'recursive' => 1,
'offset' => $offset,
'order' => array('User.status DESC','User.lastname ASC', 'distance ASC')
//'conditions' => array('User.id !=' => $user_id)
);
$results = $this->User->find('all', $params);
I’ve got this so far but cannot seem to change it so a certain user(1 user) comes in the first row of results.
Is there a solution for this in Cakephp?
The raw SQL you need might look like:
In CakePHP you should use a virtual field to create the user_sort and then just add it to your order array.
In your user model add a virtual field for user_sort:
Then you would add to your order array like so: