下面是CodeIgniter单列
where_in
子句$this->db->where_in('x1',$val);
如何在 CodeIgniter
where_in
子句中传递多个列,如下 MySQL 查询:
select *
from tab1
where (col1,col2) in ((1,2),(2,3))`
假设你的数据数组是这样的(应该是)
$val1 = array(1,2);
$val2 = array(2,3);
查询应该是
$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();
或者你可以使用
$this->db->query("select * from tab1 where (col1,col2) in ($val1,$val2)");
“$arr_1 = some_array;”
“$arr_2 = 某个数组;”
如果它们是相同的数组,只需将
$array_2
替换为 $arr_1
$result = $this->db->select('*')->where_in('col1',$arr_1)->where_in('col2',$arr_2)->get('tab1')->result_array();
或
$result = $this->db->select('*')->where_in('col1',$arr_1)->or_where_in('col2',$arr_2)->get('tab1')->result_array();