0
votes

I'm having a problem returning multiple rows dynamically.

I have an active record query that needs to return multiple rows from the same table.

//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);

It only ever seems to return the first item in the array of ids.

2
Try using $q=$this->db->select('*')->from('table_name')->where($cond)->where_in('id',$array)->get();, maybe this will work (remember to change table_name to yours); - bobo
Forgot to say, this line: $cond['id'] = implode(',',$array); needs to be removed first. - bobo
You bet thanks. You should answer the question and I'll checkmark. Thanks. - Laurence

2 Answers

0
votes

Try something like

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

Please try this, it will help you.

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

Note:- Make sure where_in array value should not empty otherwise it will get MySQL Error.