【问题标题】:cakephp use "OR" "AND" in find querycakephp 在查找查询中使用“OR”“AND”
【发布时间】:2013-06-28 08:45:46
【问题描述】:

我是 cakephp 的新手,所以我不知道如何在 cakephp 中编写此查询。有时我有这个查询

  $count = $this->User->find('count', array(
            'conditions' => array('User.mobileNo' => $mobileNo)));

此查询正在检查数据库中的手机号码是否等于用户提供的手机号码.. 我想添加另一个条件,即 手机号码等于用户提供的手机号码,电子邮件等于用户提供的电子邮件,例如

     $count = $this->User->find('count', array(
            'conditions' => array('User.mobileNo' => $mobileNo))) And
   'conditions' => array('User.email' => $email))) 

【问题讨论】:

    标签: sql cakephp cakephp-2.0 cakephp-2.1


    【解决方案1】:

    您只需添加到条件数组中:

    $count = $this->User->find('count', array(
        'conditions' => array(
            'User.mobileNo' => $mobileNo,
            'User.email' => $email
        )
    ));
    

    文档e.g.中有很多这样的例子。

    $conditions = array("Post.title" => "This is a post", "Post.author_id" => 1);
    // Example usage with a model:
    $this->Post->find('first', array('conditions' => $conditions));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多