[eluser]mvdg27[/eluser]
Hi guys,
I'm running into a problem with a query, that has both where statements and or_where statements. Not sure if it's an issue with CI, or that I'm doing something wrong in my query. The case is that I'm selecting menu-items. Now for my 'protected website'-module, I want to select only the items that are linked to the groups the logged-in user belongs to.
This query works fine for the normal menu:
Code:
$this->CI->db->where('active', 1);
$this->CI->db->where('parent', 0);
$this->CI->db->get('table');
For the protected menu, I've added a Join statement and an or_where statement:
Code:
$this->CI->db->where('active', 1);
$this->CI->db->where('parent', 0);
$this->CI->db->join('Defs', 'Defs.item_id = table.id');
$this->CI->db->group_by('id');
// loop through groups this user belongs to
foreach($this->CI->session->userdata('groups') as $group) {
$this->CI->db->or_where('group_id', $group);
}
$this->CI->db->get('table');
In this code the where statements for 'active' and 'parent' are ignored.
Any idea as to why this happens? And is there a way to fix my query?
Thanks in advance for the input.
Michiel