I am trying to show some data coming from a database in a page (VIEW) using the WHERE clause as a variable. but failed to get the expected data.
$this->db->select('vehicle.*,vec_source.vec_Source,vec_images.image1');
$this->db->from('vehicle');
$this->db->join('vec_images', 'vehicle.vec_Id = vec_images.vec_Id_fk','inner');
$this->db->join('vec_source', 'vehicle.vec_Id = vec_source.vec_Id_fk','inner');
$this->db->where_in('Make',$make);
$query = $this->db->get();
return $query->result_array();
The above query is working fine but when the variable $make is empty, then how to show full results as Where Like ='%' how to achieve this in IN Clause
Thanks In Advance
Just add where_in
using if
:
// previous code here
$this->db->join('vec_source', 'vehicle.vec_Id = vec_source.vec_Id_fk','inner');
if (!empty($make)) {
$this->db->where_in('Make',$make);
}
$query = $this->db->get();
// more code here
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.