#Thinkphp#查询语句 in

手册中解释说明:

[NOT] IN: 同sql的[not] in ,查询条件支持字符串或者数组,例如:

$map['id']  = array('not in','1,5,8');

和下面的等效:

$map['id']  = array('not in',array('1','5','8'));

查询条件就变成 id NOT IN (1,5, 8)

实际使用中遇到的问题:


$dept_id = intval(I('get.dept_id'));

if ($dept_id) {

$dept_list = A('Department', 'Event')->getDeptChildids($dept_id, 1);//获取自己以及子部门的ID,以逗号隔开返回

 $where['dept_id'] = array('in', $dept_list);
 }

查询过程中出现in中的条件丢失
运行结果:

 SELECT Elecorder.id AS id,Elecorder.num AS num,Elecorder.accept_time AS accept_time,Elecorder.expire_time AS expire_time,Elecorder.status AS status,Elecorder.appeal_content AS appeal_content,Elecorder.isleader AS isleader,Elecorder.create_time AS create_time,ElecorderAppeal.title AS appeal_title,ElecorderOrganizer.dept_id AS dept_id,ElecorderOrganizer.type AS organizer_type,ElecorderOrganizer.id AS organizer_id,Department.title AS dept_title FROM gxy_elecorder Elecorder LEFT JOIN gxy_elecorder_appeal ElecorderAppeal ON Elecorder.appeal_id = ElecorderAppeal.id LEFT JOIN gxy_elecorder_visittype ElecorderVisittype ON Elecorder.visit_id = ElecorderVisittype.id LEFT JOIN gxy_elecorder_satisfy ElecorderSatisfy ON Elecorder.satisfy_id = ElecorderSatisfy.id LEFT JOIN gxy_elecorder_organizer ElecorderOrganizer ON Elecorder.id = ElecorderOrganizer.elecorder_id And ElecorderOrganizer.ismain=1 and ElecorderOrganizer.status != 10 and ElecorderOrganizer.is_recall !=1 LEFT JOIN gxy_department Department ON Department.id = ElecorderOrganizer.dept_id WHERE ( ElecorderOrganizer.dept_id IN () ) LIMIT 0,10

最终解决结果

20140317194912

单引号问题

#Thinkphp#查询语句 in》有2个想法

发表评论

邮箱地址不会被公开。