CodeIgniter Forums
database active record class group on where clause - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: database active record class group on where clause (/thread-24365.html)



database active record class group on where clause - El Forum - 11-08-2009

[eluser]czetsuya[/eluser]
Hi,

I am using the active record class from codeigniter and it works fine, for example:

Code:
$this->db->where('name', $name);
$this->db->where('title', $title);
$this->db->where('status', $status);

//produces
// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
{codeigniter docs}

Question: is it possible to produce a grouping in WHERE?
For example:
Code:
WHERE name = 'Joe' OR (title = 'boss' AND status = 'active')

Note the parenthesis tag ( ), and the OR and AND.

Regards,
czetsuya

EDIT:

Nevermind, I've just used the custom string:

Code:
# Custom string:

You can write your own clauses manually:
$where = "name='Joe' AND status='boss' OR status='active'";

$this->db->where($where);