Combining `where` and `like` statements by using the CI activerecords

前端 未结 6 2302
一个人的身影
一个人的身影 2021-01-06 18:48

To cut a long story short: Is it possible and if it is - how can I build a query that looks somewhat like this one

SELECT * FROM a
    WHERE row = 1 AND 
            


        
6条回答
  •  情书的邮戳
    2021-01-06 19:23

    You can try this.

       $query = $this->db->select('*')
                ->from('a')
                ->where('row',1)
                ->where("(other_row LIKE '%%' OR another_row LIKE '%%' )")
                ->get();
    
    
        foreach ($query->result() as $row) {
            //do sth.
        }
    

    You can write custom query string (from active record class)

     Custom string:
     You can write your own clauses manually:
    
     $where = "name='Joe' AND status='boss' OR status='active'";
    
     $this->db->where($where);
    

提交回复
热议问题