I want a Codeigniter select query from a table with three conditions in .
1. wrk_fld_exc = 140
2. wrk_cs_sts = Open
3. wrk_dlvrd_sts = Delivered OR wrk_cl_st
codeigniter uses its own syntax for OR claus in query
$this->db->or_where('wrk_cl_sts','Success');
to use AND in where clause use $this->db->where('');
twice
$city=$params['search']['city'];
$like = "(location like '%$city%' or address like '%$city%' or city like '%$city%')";
$this->db->where($like);
$this->db->select("*");
$this->db->from("table_name");
if($condition1 != ''){
$this->db->where('wrk_fld_exc', 140);
}
if($condition2 != ''){
$this->db->where('wrk_cs_sts ', open);
}
//You can limit the results
$this->db->limit(5);
$q = $this->db->get();
return $q->result();
This is the basic structure of the query you can implement in this way in codeigniter. You can add conditions if you require.
$this->db->where('wrk_fld_exc',140);
$this->db->where('wrk_cs_sts','open');
$where = '(wrk_dlvrd_sts="open" or wrk_cl_sts = "Success")';
$this->db->where($where);
$this->db->where ('attribute',$data['attribute']);
$this->db->or_where ('attribute',$data['attribute']);
$this->db->and_where ('attribute',$data['attribute']);
You can code it like this:
$this->db->where('wrk_fld_exc',140);
$this->db->where('wrk_cs_sts','open');
$where = '(wrk_dlvrd_sts="open" or wrk_cl_sts = "Success")';
$this->db->where($where);