【问题标题】:Using where_in in delete or select query codeigniter在删除或选择查询代码点火器中使用 where_in
【发布时间】:2017-05-27 07:43:15
【问题描述】:

我正在尝试在 codeigniter 删除函数中使用 where_in。我正在分解从视图接收到的整数数组值。但是由于我需要将它们传递到 where_in 我将其内爆为:

implode(",",$delete_ids); //output: 12,13

但是当我将它传递给查询时,它显示为

SELECT * FROM (`table`) WHERE `id` IN ('12,13');

我也尝试过使用

implode("','",$delete_ids); // output:12','13

但是当我将它传递给查询函数时,它会显示:

SELECT * FROM (`table`) WHERE `id` IN ('12\',\'13') 

不要在里面放任何额外的参数。

请帮我解决这个问题...谢谢

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    您应该将一个数组传递给 where_in 而不使用 implode(....),您的代码将是这样的:

    $db->where_in('your_field', $delete_ids);
    

    【讨论】:

      【解决方案2】:

      通过codeigniter database documentation,您可以简单地使用where_in()函数。你可以使用这个:

      $this->db->where_in('id', $delete_ids);
      

      【讨论】:

        猜你喜欢
        • 2018-11-24
        • 2014-02-14
        • 2013-01-05
        • 2014-01-15
        • 2012-05-29
        • 2012-11-14
        • 2012-02-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多