Mahdi Majidzadeh Mahdi Majidzadeh - 1 month ago 7
PHP Question

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
and
WHEREIN
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??

Answer

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');
Comments