codeigniter中的多列where_in子句

时间:2017-08-16 08:37:45

标签: php mysql codeigniter where-in

下面是codeigniter单列$this->db->where_in('x1',$val);子句where_in

如何在CodeIgniter select * from tab1 where (col1,col2) in ((1,2),(2,3))子句中传递多个列,如下面的MySQL查询nodeData.items = []; $scope.newSubItem = function(scope) { var nodeData = scope.$modelValue; if(nodeData && nodeData.items ){ } }; 任何帮助表示赞赏

2 个答案:

答案 0 :(得分:0)

假设您的数据数组是这样的(应该是)

$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)");

答案 1 :(得分:0)

" $ 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();

OR

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