gpt4 book ai didi

php - 去掉()前后的 ' '

转载 作者:行者123 更新时间:2023-11-29 10:02:27 25 4
gpt4 key购买 nike

从下面的代码中我得到一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com