在()之前和之后删除''

时间:2018-10-04 04:50:54

标签: php mysql sql-server database codeigniter

从下面的代码中,我得到一个SQL查询:

SELECT * FROM `tblstaff` WHERE `active` = 1 AND role IN '(10,7,4,5)'
AND staffid IN '(3,8,9,12,2 )' AND `is_not_staff` =0 ORDER BY
`firstname` DESC

使用'()'n会使查询错误,值来自$ staffids和$ roleid,并且这是一个字符串,因此当转换为关联数组时,其输出为'(10,2,5 )”。。那么如何从查询中删除''

      if ($staff_role != STAFF_ROLE_SALE_AGENT_FTD_ID && $staff_role != STAFF_ROLE_SALE_AGENT_RETENTION_ID && ($view_own || $view )){
            if(get_staff_role() == STAFF_ROLE_ADMIN_ID){  
                $where['role NOT IN '] = "( ". STAFF_ROLE_SA_ID ." )" ; 
            } else{
                    $roleids = get_immediate_roleids();
                    if($roleids != ''){
                        $where['role IN'] = '('. $roleids .')';                
                    }
                }
            if($staff_role != STAFF_ROLE_SA_ID){
                if($view_own){
                    $staffids = get_immediate_staffids($staff_id); echo $staffids;
                    $where['staffid IN'] =  $staffids ." )" ;
                } else if(is_numeric($staff_office_id) && $staff_office_id > 0){
                        $staffids = get_immediate_staffids_under_office('', $staff_office_id);echo $staffids;
                        $where['staffid IN'] = "(". $staffids  ." )" ;
                    }
            }

1 个答案:

答案 0 :(得分:1)

如果您正在使用CI查询构建器,则必须更改方法:

替换此内容:
$ where ['role NOT IN'] =“(”。STAFF_ROLE_SA_ID。“)”;
搭配:
$ this-> db-> where_not_in('role',STAFF_ROLE_SA_ID);
并与“在条款中”相同:
$ this-> db-> where_in('staffid',$ staffids);