• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.