Codeigniter - use two types and where together

I have a problem using two similar operators 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 request is to choose LIKE1either LIKE2where WHEREand WHEREINtrue.

If I use or_like, WHEREthe get the operator ortoo,

If I use only like, it becomes an expressionlike AND like

Any solution?

+4
source share
3 answers

I found this solution:

use group_start()and group_end()so my code will turn into

$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');
+4
source

If you have a complex where clause, you can write it like this:

$this->db->where("doc = '123456' AND place IN('1,2,3') AND name (LIKE '%query%' ESCAPE '!' OR code LIKE '%query%' ESCAPE '!' )", NULL);
0
source

, ​​:

function example(){

    $query = "( SQL QUERY )";
    $search = $this->db->query($query);
    return $search->result_array(); 
}
0

Source: https://habr.com/ru/post/1605626/


All Articles