【问题标题】:codeigniter database where or_where clause solutioncodeigniter 数据库 where or_where 子句解决方案
【发布时间】:2016-05-18 23:51:24
【问题描述】:

我不知道这个 sql 查询的 codeigniter db translate

select * from table
where a=1 and (b=1 or c=1 or d=1)

$this->db->where $this->db->or_where ?!?!

有人帮我吗? 多谢 最好的问候

【问题讨论】:

    标签: php mysql sql codeigniter where


    【解决方案1】:

    我认为这是您要查找的查询。

    $query = $this->db->select("*")
             ->from("table")
             ->where("a", 1)
             ->group_start()
                        ->where("B", 1)
                        ->or_where('c', 1)
              ->group_end()
              ->get()
              ->result_array();
    
    var_dump($query);
    

    【讨论】:

      【解决方案2】:

      如果您使用doc

      你可以看到,如果你使用 or_where 你会做这样的查询

      $this->db->where('name !=', $name);
      $this->db->or_where('id >', $id); 
      
      // Produces: WHERE name != 'Joe' OR id > 50
      

      【讨论】:

      • 我在 codeigniter 解决方案中没有得到相同的查询结果,你能帮帮我吗?
      【解决方案3】:

      使用此代码。

      $this->db->select('*');
      $this->db->where('a', 1);
      $this->db->or_where('b', 1);
      $this->db->or_where('c', 1);
      $this->db->or_where('d', 1);
      

      【讨论】:

        猜你喜欢
        • 2023-03-08
        • 2013-05-06
        • 2012-04-09
        • 1970-01-01
        • 2011-06-30
        • 2012-10-31
        • 2012-10-11
        • 1970-01-01
        相关资源
        最近更新 更多