【问题标题】:How to use IN operator in Cakephp [closed]如何在 Cakephp 中使用 IN 运算符 [关闭]
【发布时间】:2014-09-17 09:50:04
【问题描述】:

对于 CakePHP 2.x 版。如果 $trs 是一个用户 id 数组,则您不必将 IN 关键字放入您的条件。您可以只留下 array("Post.user_id" => $trs) 和 Cake 将 IN 运算符添加到此查询中。整行:

$this->Post->find('all',array('conditions'=>array('Post.user_id'=>$trs), 'order' => array('Post.created DESC')));

【问题讨论】:

  • 您的编辑实际上使这个问题更糟。没有更好。

标签: php sql cakephp


【解决方案1】:

对于 CakePHP 2.x 版。如果$trs1 是一个数组,则不必将IN 关键字放在您的条件中。您可以只留下array("Post.user_id" => $trs1) 和Cake 将IN 运算符添加到此查询。整行:

$this->Post->find('all',array(
    'conditions'=> array('Post.user_id' => $trs1), 
    'order' => array('Post.id DESC')
));

【讨论】:

  • 请注意,这仅对 2.x 有效 ​​- 在 CakePHP 3.x 中,您必须添加 IN
  • 哦,谢谢,3.x版本还没看。
  • 同样适用于 cake 1.3
猜你喜欢
  • 2013-05-19
  • 2012-03-15
  • 2014-10-31
  • 2018-09-16
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-11
相关资源
最近更新 更多