有条件限制和顺序的cakephp查询 [英] cakephp query with conditions limit and order
本文介绍了有条件限制和顺序的cakephp查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用表Users
中的字段created
检索cakephp中的最后3个注册用户.
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?
推荐答案
尝试如下操作:
$this->set('users', $this->User->find('all', array(
'limit' => 3,
'order' => 'User.created DESC',
'recursive' => 1,
)));
这篇关于有条件限制和顺序的cakephp查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文