php - 如何使或未定义?
问题描述
我是 Php 的新手,我陷入了困境。
我需要制作一个类别过滤器,它是用一个复选框选中的。orWhere如何为每个类别做?
我需要类似的东西:
$users = DB::table('users')
-> where ('category_id', 1)
-> orWhere ('category_id', 2)
...
-> orWhere ('category_id', n)
-> get ();
解决方案
你应该使用whereIn
$users = DB::table('users')
->whereIn("category_id" , [1,2,...,n])
->get();
推荐阅读
- laravel - 如何使用 Laravel 中间件修复 ERR_TOO_MANY_REDIRECTS?
- swift - Swfit URLRequest POST 如何使用重复的参数键发出请求
- sql - 表值函数作为参数传递以在 case 语句中生成输出
- node.js - 预授权支付 7 天到期后触发哪个条带 webhook 事件?
- mysql - 如何在SQL中查找表中多个列的总和
- node.js - 如何在本机反应中将通过udp连接检索到的数据从子级传递到父级
- bash - 为什么等待完成的父 shell 进程不能可靠地接收从 Bash 脚本中的后台作业发送的 USR1 信号?
- node.js - MongoDB 如何在 deleteMany 中捕获错误
- android - 将代码转换为 (G+H) 后应用程序崩溃。GMS 和 HMS 支持
- php - Xampp 不加载 Codeigniter 视图子文件夹内的页面