Welcome Guest, Not a member yet? Register   Sign In
Active Record - Where filter with same keys
#1

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!
Reply
#2

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

Reply
#3

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') 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB