代码之家  ›  专栏  ›  技术社区  ›  Thiyagu

codeigniter中子句中的多列where_

  •  3
  • Thiyagu  · 技术社区  · 8 年前

    下面是codeigniter单柱 where_in 条款 $this->db->where_in('x1',$val);

    如何通过CodeIgniter中的多个列 where_in 类似MySQL查询的子句 select * from tab1 where (col1,col2) in ((1,2),(2,3)) 感谢您的帮助

    2 回复  |  直到 8 年前
        1
  •  2
  •   Abdulla Nilam    8 年前

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

    $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)");
    
        2
  •  0
  •   Shoaib Quraishi    8 年前

    “$arr\u 1=some\u数组;”

    “$arr\u 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();