Thinkphp中自己组合的数据怎样使用框架的分页
2016-05-10 18:09
731 查看
做项目有时候,需要自己处理组合数据,不是直接从表中提取出来的。不能按照手册得方法分页显示数据。这时候就得想办法,正好看到他人的方法。地址为:http://www.thinkphp.cn/code/276.html
根据自己的情况使用,我的数据处理
关键的就是这几行
出粗的话要注意语句的先后顺序。
function array_page($array,$rows){ import("ORG.Util.Page"); //导入分页类 $count=count($array); $Page=new Page($count,$rows); $list=array_slice($array,$Page->firstRow,$Page->listRows); return $list; }
根据自己的情况使用,我的数据处理
$uarr=array(); foreach($ids as $v){; $map['userid']=$v['id']; $uinfo=$u->where($map)->select();//存放下级渠道信息 $uarr[]=$uinfo[0]; } $subuser=array_filter($uarr); $count=count($subuser); $Page= new \Think\Page($count,1);// 实例化分页类 传入总记录数和每页显示的记录数 $show= $Page->show();// 分页显示输出 $list=array_slice($subuser,$Page->firstRow,$Page->listRows); $this->assign('page',$show);// 赋值分页输出 $this->assign('subuser',$list);//去除数组中的空值,然后传到模板中
关键的就是这几行
$subuser=array_filter($uarr); $count=count($subuser); $Page= new \Think\Page($count,1);// 实例化分页类 传入总记录数和每页显示的记录数 $show= $Page->show();// 分页显示输出 $list=array_slice($subuser,$Page->firstRow,$Page->listRows);
出粗的话要注意语句的先后顺序。
相关文章推荐
- PHP 的 preg_match 和 preg_match_all
- PHP性能优化
- php:mysqli扩展
- PHP中的ob_start用法详解
- 实现RTP协议的H.264视频传输系统
- FragmentPagerAdapter中的getItem()方法 第二次进入该fragment,不会被调用的问题
- Annotation实战【自定义AbstractProcessor】
- 如何debug自定义AbstractProcessor
- PHP+Mysql 实现留言板
- wdcp LNMP,php 网页显示源代码
- php的数组的函数
- php设计模式:单例模式
- php结合web uploader插件实现分片上传文件
- ThinkPHP怎样配置URL模式为PathInfo?
- ibatis removeFirstPrepend失效解决方法
- Vsftp配置都没有问题 连接不上 530 Login incorrect 解决方法
- tuzicms 2.5 zend环境检测提示未安装,无法下一步安装程序
- 联合查询 thinkPHP
- php乘法口诀
- PHP设计模式