Php Codeigniter活动记录使用多个主键选择多行
动态返回多行时遇到问题 我有一个活动记录查询,需要从同一个表返回多行Php Codeigniter活动记录使用多个主键选择多行,php,codeigniter,activerecord,Php,Codeigniter,Activerecord,动态返回多行时遇到问题 我有一个活动记录查询,需要从同一个表返回多行 //this will be a dynamic array of ids $array = array('01','02','03'); //i need to have other where conditionals as well $cond['userlevel'] = 5; //then add the array of ids to the conditionals array $cond[
//this will be a dynamic array of ids
$array = array('01','02','03');
//i need to have other where conditionals as well
$cond['userlevel'] = 5;
//then add the array of ids to the conditionals array
$cond['id'] = implode(',',$array);
//then build the active record query
$q = $this->db->select($col->where($cond);
它似乎只返回ID数组中的第一个项。尝试以下操作
"SELECT * FROM table_name WHERE userlevel IN(?,?,?,?)", array(0,1,2,3);
请试试这个,它会帮你的
$this->db->select('*');
$this->db->from('table_name');
$this->db->where_in('column_name',array(0,1,2,3));
注意:-确保数组中的where_值不应为空,否则将出现MySQL错误。尝试使用$q=$this->db->从'table_name'->where$cond->where_in'id',$array->get;,也许这会起作用记住把表名改成你的;忘了说,这行:$cond['id']=内爆',',$array;需要先删除。当然,谢谢。你应该回答这个问题,我来打勾。谢谢