How to encapsulate the logic of OR conditions with CodeIgniter's query builder methods
03:16 24 May 2017

I have this function in model

function select($table, $match, $or)
{
    $this->db->select('*');
    $this->db->from($table);
    $this->db
        ->where($match)
        ->or_where($or);
    $query = $this->db->get();
    $query_result = $query->result();
    return $query_result;
}

and in controller

$post = array(
    "class" => "XI",
    "section" => "A",
    "stream" => "Medical"
);
$data = $this->main_model->select(
    "class_subjects",
    array(
        "class" => $post['class'],
        "section" => "all",
        "stream" => $post['stream']
    ),
    $post
);
print_r($data);

I am not getting any error but this is printing whole data of table. How can I match class='XI' and stream='Medical' and (section='A' or section='all')?

php codeigniter where-clause query-builder logical-grouping