我的模型中有以下功能,可以根据会话中的用户ID选择记录。
public function getOfficer()
{
$usr = $this->session->userdata('id_user');
$userArray = $this->db->order_by('last_name','ASC')->where_in('tbl_officer.p_code', [8,10,24]);
$userArray1 = $this->db->order_by('last_name','ASC')->get_where('tbl_officer', array('status' => 1, 'usr'=>$this->session->userdata('id_user')));
if($usr == 4){
$this->db->where('p_code',$userArray );
}else{
$this->db->where('usr',$userArray1);
}
$q = $this->db->get('tbl_officer');
if ($q->num_rows() > 0) {
return $q->result();
}
return false;
}
但函数出现了错误,没有得到预期的结果。
Error Number: 42000/1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `p_code` =' at line 2
SELECT * WHERE `p_code` =
Filename: C:/xampp/htdocs/doahrm/application/models/Officer_model.php
Line Number: 106
可能出了什么问题?有人能帮忙吗?