php - 去掉()前后的 ' '

标签 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  ." )" ;
                    }
            }

最佳答案

如果您使用 CI 查询生成器,则必须更改方法:

替换这个:
$where['角色不在'] = "( ". STAFF_ROLE_SA_ID .")";
与:
$this->db->where_not_in('角色',STAFF_ROLE_SA_ID);
与Where In子句相同:
$this->db->where_in('staffid',$staffids);

关于php - 去掉()前后的 ' ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52639229/

相关文章:

php - 如何以一种形式将多个文本框发布到数据库

php - Laravel 4 中搜索结果的 anchor 标签

sql - SQL Server/Azure 中空值 "not working"的总和

SQL:在查询的其他部分引用计算列

php - 如何在 SQL 中合并两 (3) 个以上的表

php SOAP 响应为空,但__last_response不是

javascript - 从表中查询值

php - 基于 MySQL 数据渲染 HTML 复选框输入

php - 如何在不执行一长串 "OR"条件的情况下找到模型的所有记录?

php - 如何合并此分类帐上的日期?