My Code:
public function amil_export($program){
$query = $this->get_where('tbl_amil', [ 'jenis_lembaga' => '%Perorang%',
'program' => $program
]);
$query = $this->execute();
return $query;
}
And I want to make Query in SQL like This
SELECT * FROM `tbl_amil` WHERE `jenis_lembaga` LIKE '%Perorang%' OR `program` = $program
can Someone fix my code
I've got a solution for this. I've used $this->db->group_start();
and $this->db->group_end();
public function amil_export($keyword, $program) {
$this->db->select('*');
$this->db->group_start();
$this->db->like('jenis_lembaga',$keyword);
$this->db->or_like('program',$program);
$this->db->group_end();
$query = $this->db->get('tbl_amil');
// echo $this->db->last_query();
return $query->result_array();
}
Hope this helps!!
get_where
will not be able to give you the result with OR
condition in it. ( REFERENCE )
You can use like
and or_where
to get the query as you want, like so -
$query = $this->db->like('jenis_lembaga', 'Perorang')->or_where('program', $program)->get('tbl_amil')->result();
// Produces:
// SELECT * FROM `tbl_amil` WHERE `jenis_lembaga` LIKE '%Perorang%' ESCAPE '!' OR `program` = $program
You can also use query grouping
( REFERENCE ) as @Ankit Jindal suggests.
Hope it helps you.
public function amil_export($program)
{
$this->db->like('jenis_lembaga ','Perorang','both');
$this->db->or_where('program',$program);
$query=$this->db->get('tbl_amil');
return $query->result();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.