I want to retrieve the last 3 registered users in cakephp using the field created
in table Users
.
In my controller I have:
$this->User->recursive = 1;
$this->set('users',
$this->User->find('all',
array('conditions'=> array(
'limit' => 3,
'order' => array(
'created' => 'asc'
)
)
)
)
);
The code above when run returns this error:
Syntax error or access violation: 1064 You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'order = ('asc')' at line
What must I do to resolve the error?
Try something like this:
$this->set('users', $this->User->find('all', array(
'limit' => 3,
'order' => 'User.created DESC',
'recursive' => 1,
)));