在()前后删除“”

oo7oh9g9  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(274)

从下面的代码中,我得到一个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  ." )" ;
                    }
            }
nbewdwxp

nbewdwxp1#

如果使用ci查询生成器,则必须更改方法:
替换此项:
         $其中['role not in']=“(”。“员工角色”;
使用:
         $this->db->where\u not \u in('role',staff\u role\u sa\u id);
与第条中的相同:
         $this->db->where_in('staffid',$staffids);

相关问题