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/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: database active record class group on where clause (/showthread.php?tid=24365)



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);