Welcome Guest, Not a member yet? Register   Sign In
"where_not_in" -- Am I an idiot?
#1

[eluser]Daniel Walton[/eluser]
Hi, i'm using the active record class as such:

Code:
$this->db->where_not_in('id', $id);

...

Code:
$this->db->get('the_table');

Which should be excluding that particular ID from the result, right? Wrong - all ids are coming back Sad What could be wrong?
#2

[eluser]johnwbaxter[/eluser]
Is it because you need to pass it an array as the second value (even if the array only holds one value)?
#3

[eluser]Daniel Walton[/eluser]
Ahh, my bad. Knew it had to be something simple.

/Thx
#4

[eluser]Phil Sturgeon[/eluser]
audiopleb is right. where_not_in() in used to create SQL such as WHERE id NOT IN('2', '42', '35') etc.

You need to either use:

Code:
$this->db->where('id !=', $id);

// or

$this->db->where_not_in('id', array($id));

In this example, the first would make more sense.
#5

[eluser]Daniel Walton[/eluser]
Yup yup, made a simple is_array() check in my application now to call either or.




Theme © iAndrew 2016 - Forum software by © MyBB