Codeigniter Active Record使用多个主键选择多行

问题描述 投票:0回答:2

我在动态返回多行时遇到问题。

我有一个活动记录查询,需要从同一个表返回多行。

//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数组中的第一项。

php codeigniter activerecord
2个回答
0
投票

尝试类似的东西

"SELECT * FROM table_name WHERE userlevel IN(?,?,?,?)", array(0,1,2,3);

0
投票

请试试这个,它会对你有所帮助。

$this->db->select('*');
$this->db->from('table_name');
$this->db->where_in('column_name',array(0,1,2,3));

注意: - 确保where_in数组值不应为空,否则将出现MySQL错误。

© www.soinside.com 2019 - 2024. All rights reserved.