Make a CodeIgniter Database Request

Can someone help me make this request using the Codeigniter Active entry ?:

I have an int array with two values:

$prices = array( [0] => 23, [1] => 98 ); how i can make something like : return $this->db->query("select * from product where price IN (?)", array(implode(',',$prices))->result(); 

Any help please.

+4
source share
2 answers

Try this one (untested)

 $query = $this->db->from('product') ->where_in('price', implode(',',$prices)) ->get(); 

CodeIgniter Active Record docs are very good, so you should definitely read about it. For example, you will notice that the select() method is not needed, since we want all elements to be accepted as * .

+1
source

try it

 return $this->db->query("select * from product where price IN ('". implode(',',$prices)->result()."' )"); 
0
source

All Articles