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','
三,分页样式,与第二种有一点点差别,有文字输出
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; }