combining mysql AND OR queries in Codeigniter
In CodeIgniter 3 there are new methods group_start() and group_end() which serve exactly for this purpose.
return $this->db ->where('LastName', 'Svendson'); ->where('Age', 12); ->group_start() ->where('FirstName','Tove') ->or_where('FirstName','Ola') ->or_where('Gender','M') ->or_where('Country','India') ->group_end() ->get('Persons') ->result();
and this will work?
$this->db->where('LastName', 'Svendson');$this->db->where('Age', 12);$this->db->where("(FirstName='Tove' OR FirstName='Ola' OR Gender='M' OR Country='India')", NULL, FALSE);$query = $this->db->get('Persons');return $query->result();
using codeigniter 3.0 frame work,there is new feature available for separate or where and where operation.that is,group by and group end
code like,
$this->db->where('LastName', 'Svendson');$this->db->where('Age', 12);$this->db->group_start();$this->db->or_where('FirstName','Tove');$this->db->or_where('FirstName','Ola');$this->db->or_where('Gender','M');$this->db->or_where('Country','India');$this->db->group_end();$query = $this->db->get('Persons');return $query->result();