codeigniter 中的多列 where_in 子句

Multiple column where_in clause in codeigniter

下面是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();