业务经理

微信扫描以上二维码

028-61286886

技术咨询

where语法拼接问题

迅睿框架 更新 2025-10-01 11:35:34 PHP学生

$where[] = 'keyword LIKE "%'.$data['keyword'].'%"';
$where[] = 'name LIKE "%'.$data['keyword'].'%"';
$where[] = '`'.$table.'`.`catids` LIKE "%\"'.intval($c).'\"%"';

在模型中使用->where($where)时,$where[0]会变成0默认不是数字,sql中体现为,出现拼接错误,如果使用where()这个有办法规避吗?

SELECT 
`id`, `keyword`, `keyword_id`
FROM `jm_keyword_rank` 
WHERE 
`search_engine` = 'baidu_pc' 
AND 
0 = 'keyword LIKE \"%ASE光源%\"' 
GROUP BY 
`keyword_id` 
ORDER BY 
`inputtime` DESC LIMIT 10

方案

  • 迅睿官方技术专家 #1 · 2025-10-01 08:35:15
    ->where(implode(" AND ", $where))
  • PHP学生 #2 · 2025-10-01 08:58:56

    目前就是这样处理的,这个是bug 吗?

    如果直接写sql 调用$this->query($sql),查不出数据,在sql中就可以查到数据,这个是啥原因的?

  • 迅睿官方技术专家 #3 · 2025-10-01 10:33:34
    不是bug,where不能传入数组格式啊
  • PHP学生 #4 · 2025-10-01 10:48:20
    哦,但是第二个数组就没有问题了,就第一个有这样的问题。如果是多组where,不使用数组,是要自己拼接成一个吗?好像where()只做一些简单的赋值,复杂的就不行。比如:
    $where[] = '`top_rank` <= 10';
    
    $where[] = '`top_rank` <= 20';
    
    $where[] = '`top_rank` <= 30';
    
    $where[] = '`keyword` LIKE "%'.$data['keyword'].'%"';
    
    $where[] = '`search_engine` = "baidu_pc"';
  • 迅睿官方技术专家 #5 · 2025-10-01 11:10:02
    满意答案
    $where[] = '`top_rank` <= 10';
    
    $where[] = '`top_rank` <= 20';
    
    $where[] = '`top_rank` <= 30';
    
    $where[] = '`keyword` LIKE "%'.$data['keyword'].'%"';
    
    $where[] = '`search_engine` = "baidu_pc"';
    ->where(implode(" AND ", $where)) 这样

    或者
    ->where('`top_rank` <= 10')->where('`top_rank` <= 20')->where('`top_rank` <= 30')
  • PHP学生 #6 · 2025-10-01 11:14:09
    迅睿官方技术专家 使用的是这种->where(implode(" AND ", $where)),还是要自己处理
    $where[] = '`top_rank` <= 10';
    
    $where[] = '`top_rank` <= 20';
    
    $where[] = '`top_rank` <= 30';
    这个要自己去替换存在的,使用起来不是很方便,还要单独写方法。

  • PHP学生 #7 · 2025-10-01 11:35:34
    @迅睿官方技术专家:结帖结帖结帖结帖结帖结帖结帖结帖结帖

迅睿系统漏洞

在线考试竞赛系统
在线考试竞赛系统(2026-09-12)
增加投票功能 考试功能拓展 注意:更新后需要执行系统更新,更新数...
网上信箱
网上信箱(2026-09-12)
修复新版本兼容问题
GeoSeo收录宝
GeoSeo收录宝(2026-09-12)
1 优化Update.php文件,解决版本在线升级不完整问题 2 ...
GeoSeo工具箱
GeoSeo工具箱(2026-09-11)
修正历史记录推送
微信系统
微信系统(2026-09-11)
增加数据统计总览界面 账号管理增加服务和公众号的区别 菜单管理支持更...
答题系统
答题系统(2026-09-11)
一站式在线答题系统,支持真题考试、题库练习和错题本,适合培训、考证、...
阿里云滑动验证码
阿里云滑动验证码(2026-09-10)
采用阿里云验证码替换迅睿系统自带的图片验证码和滑动验证码。后台设置方...
下载Plus
下载Plus(2026-09-09)
为网站附件下载加上“计数、限次、统计、防护”四重能力:按用户组控制下...
全库搜索
全库搜索(2026-09-09)
修复全模块搜索时,删除按钮点击无效的bug
在线客服
在线客服(2026-09-09)
增加消息提示音