当前位置: 首页 > news >正文

【PHP】where和whereOr一起复杂查询示例

在ThinkPHP 5 中,where 和 whereOr 方法可以一起使用以实现复杂的查询条件。以下是一个示例:

// 接收的参数
$param = $this->request->param();// 实例化
$query = new UserModel();// 关联表
$query->with(['collect' => function($collect_query) use ($user_id) {$collect_query->field('id,user_id');$collect_query->where('user_id', user_id);
}]);// 查询条件
$query->where(['status' => 1])// 可筛选逗号分割的
$query->where("FIND_IN_SET({$user_id},parent_ids)")// 价格区间最小值
if(isset($param['min_money']) && is_numeric($param['min_money'])){$query->where(function ($query) use ($param) {$query->where('price_min', '>=', $param['min_money'])->orWhere('price_max', '>=', $param['min_money']);});
}// 价格区间最大值
if(isset($param['max_money']) && is_numeric($param['max_money'])){$query->where(function ($query) use ($param) {$query->where('price_min', '<', $param['max_money'])->orWhere('price_max', '<', $param['max_money']);});
}// 查询结果
$list = $query->field(TaskModel::HALLLIST)->order($sort)->select();

http://www.lryc.cn/news/274572.html

相关文章:

  • Mysql 动态链接库配置步骤+ 完成封装init和close接口
  • 哈希一致性算法
  • 基于SpringBoot的在线考试系统绿色
  • 设计模式:原型模式
  • Qt5+VS2013兼容XP方法
  • GitHub Copilot 最佳免费平替:阿里通义灵码
  • 体系化的进阶学习内容
  • SpringBoot解决前后端分离跨域问题:状态码403拒绝访问
  • 【linux】更改infiniband卡在Debian系统的网络接口名
  • SPRING BOOT发送邮件验证码(Gmail邮箱)
  • Liunx安装FTP和SFTP
  • 【Mars3d】new mars3d.layer.GeoJsonLayer({不规则polygon加载label不在正中间的解决方案
  • 怎么快速修复mfc140.dll文件?解决mfc140.dll缺失的方法
  • 安全防御之入侵检测与防范技术
  • Leetcode2807. 在链表中插入最大公约数
  • MySQL-DML
  • 开源项目 | 完整部署流程、一款开源人人可用的开源数据可视化分析工具
  • 我建立了一个资源分享群
  • C++中几个常用的类型选择模板函数
  • 【LeetCode】1321. 餐馆营业额变化增长
  • 【网络技术】【Kali Linux】Wireshark嗅探(八)动态主机配置协议(DHCP)
  • 算法29:不同路径问题(力扣62和63题)--针对算法28进行扩展
  • openGauss学习笔记-188 openGauss 数据库运维-常见故障定位案例-core问题定位
  • kubernetes入门到进阶(5)
  • 【字典树Trie】LeetCode-139. 单词拆分
  • pytest常用的第三方插件介绍
  • 【经验】VSCode连接远程服务器(可以使用git管理、方便查看和编辑Linux源码)
  • 机器学习-生存分析:如何基于随机生存森林训练乳腺癌风险评估模型?
  • MySQL学习笔记1: 数据库的简单介绍
  • 【Docker】安装ELK(Docker Compose)