Backstage
1. Paging using the Page class and limit method
$User = M('User'); // 实例化User对象
$count = $User->where('status=1')->count();// 查询满足要求的总记录数
$Page = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)
$show = $Page->show();// 分页显示输出
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
$list = $User->where('status=1')->order('create_time')->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('list',$list);// 赋值数据集
$this->assign('page',$show);// 赋值分页输出
$this->display(); // 输出模板
2. Implementation of paging class and page method
$User = M('User'); // 实例化User对象
// 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
$list = $User->where('status=1')->order('create_time')->page($_GET['p'].',25')->select();
$this->assign('list',$list);// 赋值数据集
$count = $User->where('status=1')->count();// 查询满足要求的总记录数
$Page = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
$show = $Page->show();// 分页显示输出
$this->assign('page',$show);// 赋值分页输出
$this->display(); // 输出模板
3. Bring in query conditions
If it is a POST query, how to ensure that the original query conditions can be maintained after paging? We can pass in parameters to the paging class by assigning a value to the parameter property of the paging class
$count = $User->where($map)->count();// 查询满足要求的总记录数
$Page = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
//分页跳转的时候保证查询条件
foreach($map as $key=>$val) {
$Page->parameter[$key] = urlencode($val);
}
$show = $Page->show();// 分页显示输出
Front desk
<ul class="paginList pager"><!-- 分页显示 -->{$page}</ul>
If the front desk directly displays
{$page}
Another way
<ul class="paginList pager">
<!-- 分页显示 -->
<?php
echo $page;
?>
</ul>