Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter - use two like and where together

I have a problem with use two like statement and where together:

    $this->db->select('something');
    $this->db->where('WHERE',$var);
    $this->db->where_in('WHEREIN', $var);
    $this->db->like('LIKE1',$query);
    $this->db->or_like('LIKE2',$query);
    $query = $this->db->get('table');

My query must select LIKE1 or LIKE2 where WHERE andWHEREIN is true.

If I use or_like, where statement get or too,

If i use just like, it's become like AND like statement

Any solution??

like image 691
Mahdi Majidzadeh Avatar asked Sep 02 '15 19:09

Mahdi Majidzadeh


1 Answers

I found this solution:

use group_start() and group_end(), so my code turn to

$this->db->select('something');
$this->db->where('WHERE',$var);
$this->db->where_in('WHEREIN', $var);
$this->db->group_start();
$this->db->like('LIKE1',$query);
$this->db->or_like('LIKE2',$query);
$this->db->group_end();
$query = $this->db->get('table');
like image 143
Mahdi Majidzadeh Avatar answered Oct 15 '22 21:10

Mahdi Majidzadeh