简体   繁体   中英

Multiple column where_in clause in codeigniter

Below is codeigniter single column where_in clause $this->db->where_in('x1',$val);

how can I pass multiple column in CodeIgniter where_in clause like below MySQL query select * from tab1 where (col1,col2) in ((1,2),(2,3)) Any help appreciated

Assume your data array is like this(should be)

$val1 = array(1,2);
$val2 = array(2,3);

And query should be

$this->db->select('*');
$this->db->from('tab1');
$this->db->where_in('col1',$val1);
$this->db->or_where_in('col2',$val2);
$query = $this->db->get();
$result = $query->result_array();

Or else you can use

$this->db->query("select * from tab1 where (col1,col2) in ($val1,$val2)");

"$arr_1 = some_array;"

"$arr_2 = some array;"

If they are the same array just replace $array_2 with $arr_1

$result = $this->db->select('*')->where_in('col1',$arr_1)->where_in('col2',$arr_2)->get('tab1')->result_array();

OR

$result = $this->db->select('*')->where_in('col1',$arr_1)->or_where_in('col2',$arr_2)->get('tab1')->result_array();

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