Reputation: 17576
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?
Upvotes: 1
Views: 2569
Reputation: 5798
use IN
clause like
$this->db->where('a.PreferenceID NOT IN (
SELECT PreferenceParentID FROM '.$table.'
WHERE EntityID IN ('.implode(",", $array).'))',
NULL, FALSE
);
Upvotes: 3
Reputation: 28755
use
'SELECT PreferenceParentID FROM '.$table.' WHERE EntityID IN ('.implode(',', $arr_id).')'
Upvotes: 1