|
本帖最后由 周大胖子 于 2018-9-4 22:34 编辑
- // 页码
- $page = $request->param('page');
- // 每页条数
- $limit = $request->param('limit');
- // limit 初始条数
- $binLimit = ($page-1)*$limit;
- // 搜索条件
- $gid = $request->param('gid');
- $status = $request->param('status');
- $truename = $request->param('truename');
- $username = $request->param('username');
- $lmsc=array();
- $gid && $lmsc['gid'] = ['=',$gid];
- $status && $lmsc['status'] = ['=',$status];
- $username && $lmsc['username'] = ['=',$username];
-
-
- // $gid && array_push($lmsc,'gid'=>['=',$gid]); 这句话是错的
- // 拼凑条件
- $where = function ($query) use($gid,$status,$truename,$username,$lmsc){
- $query->where($lmsc);
- };
- // 获取总页数 总条数数/每页条数 判断% 在这里利用 ceil 运算符
- // $count = ceil(count(Admins::all())/$limit); 这是页码数 但是 layui返回的是条数
- $count = count(Admins::all($where));
- // 获取分页信息
- $list = Admins::order('gid asc,add_time desc')->limit($binLimit,$limit)->select($where);
- exit( json(0,'加载成功',$count, $list) );
复制代码 依照老莫我目前粗浅的见识,多条件查询的原理 就是1.先接收条件;
2.判断是否有值;
3.搞个空数组用来存放搜索条件 where;
4.有值就存出来,存到这个数组里;
参考文献:https://blog.csdn.net/haibo0668/article/details/78203170
|
|