【问题标题】:Multiple column where_in clause in codeignitercodeigniter 中的多列 where_in 子句
【发布时间】:2017-08-16 08:37:45
【问题描述】:

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

如何在 CodeIgniter where_in 子句中传递多个列,如下面的 MySQL 查询 select * from tab1 where (col1,col2) in ((1,2),(2,3)) 任何帮助表示赞赏

【问题讨论】:

    标签: php mysql codeigniter where-in


    【解决方案1】:

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

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

    【讨论】:

    • 例如,我只更新了 col1 = 1 或 2 和 col2 = 2 或 3 的地方,但这也更新了 col1=1 和 col2=3
    • 更改它并查看$this->db->or_where_in('col2',$val2);
    • $data = array(approve' => 1); $this->db->where_in('third_id', $t_id); $this->db->where_in('_id', $s_id); $this->db->update(TAB, $data);
    • OR 也会发生同样的事情
    • 乐于助人:)
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2020-03-26
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      相关资源
      最近更新 更多