简体   繁体   中英

how can i pass array in where clause with codeigniter?

How can I pass an array variable in where clause with codeigniter? For example with a SQL query like:

Select(" item,price Where(userid=123 and proid=3 or userid=124 and proid=3... [upto n user id]userid=nth_id and proid=3");

If userid is stored in an array variable then how can I create such a condition in codeigniter?

I you are looking for this, it should look for a userid that is in the array and also has a proid of 3. I have not tested it but let us know how you get on.

$array = array( '123', '124' );
$this->db
     ->select( 'item, price' )
     ->from( 'table')
     ->where( 'proid', '3' )
     ->where_in( 'userid', $array )
     ->get();
$result = $query->result();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM