Codeigniter Active Record 'where_or' grouping

前端 未结 3 1780
你的背包
你的背包 2020-12-11 04:00

Is it possible to group and_where / or_where / or_like... statements together so as not to mix with other and/where statements.

Something that would result

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 04:40

    Yes. $this->db->where() allows you to write clauses manually. You could do this:

    $this->db->where('city', 'My City');
    $this->db->where('state', 'My State');
    $this->db->where('(name LIKE %name1% OR name LIKE %name2%)', null, false);
    

    Setting the third parameter for false prevents CodeIgniter from trying to add backticks to the clause.

    Check out the Active Record documentation. The section titled $this->db->where(); explains the four methods you can use to set WHERE clauses.

提交回复
热议问题