CodeIgniter Active Record Where Not In String

强颜欢笑 提交于 2020-01-30 04:09:11

问题


I'm having an issue with CI Active Record's "Where Not In". I am trying to exclude a series of ID's. I couldn't understand why everything worked fine and dandy with one record, but not with multiple.

My Query

$this->db->where_not_in('crm.user_id', $ignore);

The problem is when I profile the the Query is wrong.

With a string of ID's

// $ignore = "12,13";    
SELECT *
FROM (`crm`)
WHERE `crm`.`user_id` NOT IN ('16,13') 
AND `survey` =  1 

With a string of Quotes ID's

// $ignore = "'12','13'";
SELECT *
FROM (`crm`)
WHERE `crm`.`user_id` NOT IN ('\'16\',\'13\'') 
AND `survey` =  1 

Am I forced to do a loop of "or_where_not_in" or something like that?


回答1:


where_in and where_not_in expect you to pass an array, not a string as the 2nd parameter.

$ignore = array(12, 13);

$this->db->where_not_in('crm.user_id', $ignore);

Link to the docs: http://www.codeigniter.com/userguide2/database/active_record.html



来源:https://stackoverflow.com/questions/16673933/codeigniter-active-record-where-not-in-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!