Christeen Christeen - 1 year ago 123
PHP Question

codeigniter where_not_in not working

I pass an array to my model and I want to get the employee_id s which are not in that array. Also 'position' field should be equal to 'c'.
Following is my table.
emp_position table

Following is my model. $evdata is a number passed to the model to limit the selecting records. Also the array $data is json encoded array.

public function get_camaramens($data,$evdata)

return $query->result();


It doesn't give a correct result. So I removed the following part and checked.


Both times it gives the same result. It seems only the first where condition is working.

[Following is the var_dump result of both times.][2]

After adding the code

$data = $this->emp_event_model->get_current_employees($date);

$newData = array();
foreach($data as $row) {
$newData[] = $row['employee_id'];
$data = $newData;

It gives this error
enter image description here

Answer Source

your $data array must be in this format

array(2, 3, 7, 8, 9)

but your array is

array (size=5) 
0 => object(stdClass)[26] public 'employee_id' => string '2' (length=1) 
1 => object(stdClass)[27] public 'employee_id' => string '3' (length=1) 
2 => object(stdClass)[28] public 'employee_id' => string '7' (length=1) 
3 => object(stdClass)[29] public 'employee_id' => string '8' (length=1) 
4 => object(stdClass)[30] public 'employee_id' => string '9' (length=1) 

so restructure your array inside your controller

$newData = array();
foreach($data as $row) {
    $newData[] = $row->employee_id;
$data = $newData;

so this will become

array(2, 3, 7, 8, 9)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download