我将一个数组传递给我的模型,我希望获得不在该数组中的employee_id。还有'位置'字段应该等于' c'。
以下是我的表:
以下是我的模特。 $ evdata是传递给模型的数字,用于限制选择记录。数组$ data也是json编码数组。
public function get_camaramens($ data,$ evdata) {
$this->db->select('emp_position.employee_id');
$this->db->from('emp_position');
$this->db->where('emp_position.position','c');
$this->db->where_not_in('emp_position.employee_id',$data);
$query=$this->db->get('',$evdata);
return $query->result();
}
它没有给出正确的结果。所以我删除了以下部分并进行了检查。
$this->db->where_not_in('emp_position.employee_id',$data);
两次都给出相同的结果。似乎只是条件有效的第一个。
以下是两次的var_dump结果:
添加代码后
$data = $this->emp_event_model->get_current_employees($date);
$newData = array();
foreach($data as $row) {
$newData[] = $row['employee_id'];
}
$data = $newData;
它给出了这个错误:
答案 0 :(得分:0)
您的$data
数组必须采用此格式
array(2, 3, 7, 8, 9)
但您的数组是
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)
重新调整控制器内的数组
$newData = array();
foreach($data as $row) {
$newData[] = $row->employee_id;
}
$data = $newData;
所以这将成为
array(2, 3, 7, 8, 9)