【问题标题】:How to pass an array to where condition in CodeIgniter?如何将数组传递给 CodeIgniter 中的 where 条件?
【发布时间】:2012-01-31 08:59:30
【问题描述】:

我在我的应用程序中使用CodeIgniter。我有这样的代码

$this->db->where('a.PreferenceID NOT IN (SELECT PreferenceParentID FROM '.$table.' WHERE EntityID='.$shop_id.')', NULL, FALSE);

我想传递 array 而不是 $shop_id

喜欢

$arr = array(1,3,5);

WHERE EntityID='. $arr.'

等于

WHERE (EntityID='. $arr[0].' OR EntityID='. $arr[1].' OR EntityID='. $arr[2].')

因为我想检查多个商店 ID。最好的方法是什么?

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    使用IN 子句喜欢

    $this->db->where('a.PreferenceID NOT IN (
        SELECT PreferenceParentID FROM '.$table.' 
        WHERE EntityID IN ('.implode(",", $array).'))',
        NULL, FALSE
    );
    

    【讨论】:

      【解决方案2】:

      使用

      'SELECT PreferenceParentID FROM '.$table.' WHERE EntityID IN ('.implode(',', $arr_id).')'
      

      【讨论】:

        【解决方案3】:

        试试类似的东西

        WHERE EntityID IN('.implode(',', $arr).')
        

        【讨论】:

          猜你喜欢
          • 2017-01-23
          • 1970-01-01
          • 1970-01-01
          • 2015-07-07
          • 1970-01-01
          • 2014-04-21
          • 1970-01-01
          • 1970-01-01
          • 2020-02-17
          相关资源
          最近更新 更多