thinkphp分页二,分装到funciton.php
function.php代码
<?php /* 全局分页 * $table 数据表名 * $order 排序 * $pagesize 每页显示N个 * $where 查询条件 * $rollPpage 控制分页 循环显示个数 */ function getpage($table,$pagesize,$order,$where='',$rollPpage='10'){ $m = M($table); $count = $m->where($where)->count();// 查询满足要求的总记录数 $page = new \Think\Page($count,$pagesize);// 实例化分页类 传入总记录数和每页显示的记录数(25) $page->listRows = $pagesize; $page->rollPage = $rollPpage; $show = $page->show();// 分页显示输出 $list = $m->where($where)->order($order)->limit($page->firstRow.','.$page->listRows)->select(); $pages['list'] = $list; $pages['show'] = $show; return $pages; }
php引用代码
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); $table = 'stock_log'; $pagesize = '10'; $order = 'id desc'; $pages = getpage($table,$pagesize,$order,$where); //格式化数据 foreach($pages['list'] as $k=>$v){ $pages['list'][$k]['local_add_time'] = date('Y-m-d H:i:s',$v['add_time']); }