phpcodeigniteractiverecordwhere-clausequery-builder

WHERE clause with two conditions separated by OR using CodeIgniter's query building methods


I am using the following code to select from a MySQL database in a CodeIgniter webapp:

$query = $this->db
    ->get_where('mytable', array('id' => 10));

This works great, but I want to write the following MySQL statement using CI query builder methods.

SELECT *
FROM `mytable`
WHERE `id`='10' OR `field`='value'

Solution

  • $where = "name='Joe' AND status='boss' OR status='active'";
    
    $this->db->where($where);