thinkphp 分页

<?php
namespace Admin\Controller;
use Think\Controller;
class GoodsController extends Controller {
	public $gm;
	public function __construct(){
		parent::__construct();//继承父类的构造方法
		$this->gm=D('goods');

	}
      public function goodslist(){
           $p=I('P')?I('P'):1;//让其打开默认为第一页
            // 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
            $list = $this->gm->order('goods_id')->page($p.',7')->select();//每页显示7条按照goods_id排序
            $this->assign('list',$list);// 赋值数据集
            $count = $this->gm->count();// 查询满足要求的总记录数
            $Page = new \Think\Page($count,7);// 实例化分页类 传入总记录数和每页显示的记录数
            $show = $Page->show();// 分页显示输出
            $this->assign('page',$show);// 赋值分页输出在模板中用$page表示
            $this->display(); // 输出模板
    }
     

}
然后在html模板中记得将分页改成  {$page}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值