thinkPHP6查询数据做筛选可以多种写法形式,直接上干货:如下
//方式一 实例化model
$keyword = $this->request->param('keyword','');
$user = new User();
$user->where('stat','=',1)->where('age','>',30)->whereLike('name','%'.$keyword.'%')->select();
//方式二 把所有的查询条件重组成一个二维数组
$map = [];
$map[] = ['age','>',30];
$map[] = ['stat','=',1];
$map[] = ['name','like','%'.$keyword.'%'];
$user->where($map)->select();
以上内容仅供参考,希望能帮助到大家!
本文介绍了在ThinkPHP6中使用两种不同的查询方式来筛选数据:一是通过实例化model并链式调用where方法,二是将所有条件组合成二维数组。这两种方法都展示了如何在查询时进行条件筛选。
431

被折叠的 条评论
为什么被折叠?



