如何传递数组到CodeIgniter的where条件? [英] How to pass an array to where condition in CodeIgniter?

查看:107
本文介绍了如何传递数组到CodeIgniter的where条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


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


传递数组而不是 $ shop_id



  $ arr = array ); 

WHERE EntityID ='。 $ arr。'

它将等于

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

因为我想检查多个商店id。 c>使用 IN

p>

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


I am using CodeIgniter in my application. I have a code like this

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

I want to pass an array instead of $shop_id.

Like

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

WHERE EntityID='. $arr.'

it will be equal to

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

Because I want to check with multiple shop id's. What is the best way?

解决方案

use IN clause like

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

这篇关于如何传递数组到CodeIgniter的where条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆