博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
thinkphp分页
阅读量:5763 次
发布时间:2019-06-18

本文共 5074 字,大约阅读时间需要 16 分钟。

thinkphp默认分页

html代码

{$page}

一:最简单的分页

$m = M('stock_log');        $page = I('get.page');        $order = 'id desc';        $where = '';                        $count      = $m->where($where)->count();// 查询满足要求的总记录数        $Page       = new \Think\Page($count,2);// 实例化分页类 传入总记录数和每页显示的记录数(25)                        $show       = $Page->show();// 分页显示输出                        $list = $m->where($where)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();        foreach($list as $k=>$v){            $list[$k]['local_add_time'] = date('Y-H-d H:i:s',$v['add_time']);            }        $this->assign('note',$list);        $this->assign('page',$show);

 二,分页样式

if(IS_POST){            $files['depot_id'] = I('post.depot_id')    ;            $files['keywords'] = I('post.keywords')    ;        }                if($files['depot_id']){            $where['depot_id'] = $files['depot_id'];            }        if($files['keywords']){            $where['_string'] = ' (goods_name like "%'.$files['keywords'].'%")  OR ( goods_barcode like "%'.$files['keywords'].'") ';        }        $this->assign('files',$files);                                $m = M('stock_log');        $page = I('get.page');        $order = 'id desc';                $pagesize = '15';                $count      = $m->where($where)->count();// 查询满足要求的总记录数        $page       = new \Think\Page($count,$pagesize);// 实例化分页类 传入总记录数和每页显示的记录数(25)        $page->listRows = $pagesize;        $page->rollPage = '10';        $page->lastSuffix=false;        $page->setConfig('header','
  • %TOTAL_ROW%条记录  每页%LIST_ROW%条  第%NOW_PAGE%页/共%TOTAL_PAGE%
  • '); $page->setConfig('prev','上一页'); $page->setConfig('next','下一页'); $page->setConfig('last','末页'); $page->setConfig('first','首页'); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $show = $page->show();// 分页显示输出 $list = $m->where($where)->order($order)->limit($page->firstRow.','.$page->listRows)->select(); foreach($list as $k=>$v){ $list[$k]['local_add_time'] = date('Y-H-d H:i:s',$v['add_time']); } $this->assign('note',$list); $this->assign('page',$show);

    三,分页样式,与第二种有一点点差别,有文字输出

    if(IS_POST){            $files['depot_id'] = I('post.depot_id')    ;            $files['keywords'] = I('post.keywords')    ;        }                if($files['depot_id']){            $where['depot_id'] = $files['depot_id'];            }        if($files['keywords']){            $where['_string'] = ' (goods_name like "%'.$files['keywords'].'%")  OR ( goods_barcode like "%'.$files['keywords'].'") ';        }        $this->assign('files',$files);                                $m = M('stock_log');        $page = I('get.page');        $order = 'id desc';                $pagesize = '15';                $count      = $m->where($where)->count();// 查询满足要求的总记录数        $page       = new \Think\Page($count,$pagesize);// 实例化分页类 传入总记录数和每页显示的记录数(25)        $page->listRows = $pagesize;        $page->rollPage = '10';        $show       = $page->show();// 分页显示输出        $list = $m->where($where)->order($order)->limit($page->firstRow.','.$page->listRows)->select();        foreach($list as $k=>$v){            $list[$k]['local_add_time'] = date('Y-H-d H:i:s',$v['add_time']);            }        $this->assign('note',$list);        $this->assign('page',$show);

     

    自己写代码

    public function purchase_list($page,$pagesize,$order,$files){        $m = M('purchase');        $link = '';        if($files['depot_id']){            $where['depot_id'] = $files['depot_id'];            $link .= '&depot_id='.$files['depot_id'];            }        if($files['keywords']){            $where['purchase_sn'] = array('like','%'.$files['keywords'].'%');                $link .= '&keywords='.$files['keywords'];            }                    $count = $m->where($where)->count();        $totalpage = ($count%$pagesize)>0?intval(($count/$pagesize))+1:$count/$pagesize;                        $page = empty($page)?1:$page;        $firstpage = '1';        $prevpage = ($page-1)<1?1:($page-1);        $nextpage = ($page+1)>$totalpage?$totalpage:($page+1);        $lastpage = $totalpage;                        $url = U('pur/index');                $pages['count'] = $count;        $pages['page'] = $page;        $pages['totalpage'] = $totalpage;        $pages['firstpage'] = $url."?page=".$firstpage.$link;        $pages['prevpage'] = $url."?page=".$prevpage.$link;        $pages['nextpage'] = $url."?page=".$nextpage.$link;        $pages['lastpage'] = $url."?page=".$lastpage.$link;                                    $list = $m->where($where)->page($page,$pagesize)->order('id desc')->select();        // 格式化字段        foreach($list as $k=>$v){            $list[$k]['local_time'] =  date('Y-m-d',$v['time']);            $list[$k]['local_total_price']  = local_price($v['total_price']);            }                $pur['list']        = $list;        $pur['pages']       = $pages;        $pur['files']       =$files;        return $pur;                 }

     

    转载地址:http://wfwux.baihongyu.com/

    你可能感兴趣的文章
    2016/08/25 The Secret Assumption of Agile
    查看>>
    (Portal 开发读书笔记)Portlet间交互-PortletSession
    查看>>
    搭建vsftpd服务器,使用匿名账户登入
    查看>>
    AMD改善Linux驱动,支持动态电源管理
    查看>>
    JAVA中循环删除list中元素的方法总结
    查看>>
    Java虚拟机管理的内存运行时数据区域解释
    查看>>
    人人都会深度学习之Tensorflow基础快速入门
    查看>>
    ChPlayer播放器的使用
    查看>>
    js 经过修改改良的全浏览器支持的软键盘,随机排列
    查看>>
    Mysql读写分离
    查看>>
    Oracle 备份与恢复学习笔记(5_1)
    查看>>
    Oracle 备份与恢复学习笔记(14)
    查看>>
    分布式配置中心disconf第一部(基本介绍)
    查看>>
    Scenario 9-Shared Uplink Set with Active/Active uplink,802.3ad(LACP)-Flex-10
    查看>>
    UML类图中的六种关系
    查看>>
    探寻Interpolator源码,自定义插值器
    查看>>
    一致性哈希
    查看>>
    mysql(待整理)
    查看>>
    看雪论坛502,出现安全宝?
    查看>>
    使用PullToRefresh实现下拉刷新和上拉加载
    查看>>