CodeIgniter Forums
Active Record - Where filter with same keys - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: Active Record - Where filter with same keys (/showthread.php?tid=617)



Active Record - Where filter with same keys - CiUser - 12-26-2014

Hi team, I'm having an issue when trying to build a where filter with same keys. Example
PHP Code:
$where = array(
     
"state <>" => "foo"
     
"state <>" => "bar",
); 
In the example the query build like "WHERE state <> 'bar'" because of the first element of the array is overridden by the sencond one.

Any solution?

Thanks in advance!


RE: Active Record - Where filter with same keys - Rufnex - 12-26-2014

Try a simple trick with an space

PHP Code:
$where = array(
     
"state <>" => "foo"
     
" state <>" => "bar",
); 

Otherwise you can do it for each where with where (for and logic) or with or_where (for or logic) like

PHP Code:
$this->db->where('state <>''foo'); 
$this->db->where('state <>''bar'); 



RE: Active Record - Where filter with same keys - includebeer - 12-26-2014

For multiple values it's best to use "where in ()" or "where not in ()"

PHP Code:
$this->db->where_not_in('state', array('foo''bar'));
// Produces: WHERE state NOT IN ('foo', 'bar')