今日头条 焦点资讯 营销之道 企业报道 淘宝运营 网站建设 软件开发 400电话
  当前位置: 首页 » 资讯 » 软件开发 » 正文

php基础分页类代码详解

放大字体  缩小字体 发布日期:2018-02-24  来源:企业800网  作者:新格网  浏览次数:421  【去百度看看】
核心提示:本文主要和大家分享php基础分页类代码详解,希望能帮助到大家。
本文主要和大家分享php基础分页类代码详解,希望能帮助到大家。

class Page

{

public $limit;	//存储limit条件

public $allPage;	//存储总页数

public $current;	//存储当前页

public $total;	//存储总条数

public function __construct($total, $num = 5)

{

//计算总页数

$this->allPage = ceil($total/$num);

//处理当前页

$this->current();

//3,3  6,3

$this->limit = (($this->current-1)*$num).','.$num;

$this->total = $total;

}

protected function current()

{

$p = isset($_GET['p']) ? $_GET['p'] : 1;

// $p = max(1, $p);	//最小不能小于1

// $p = min($p, $this->allPage);//最大不能超过总页数

if ($p < 1) $p = 1;

if ($p > $this->allPage) $p = $this->allPage;

$this->current = (int)$p;

}

public function show()

{

$first = $end = $pre = $next = $_GET;//处理上一页$pre['p'] = $this->current - 1;

$preStr = http_build_query($pre);

//处理下一页$next['p'] = $this->current + 1;$nextStr = http_build_query($next);

//处理首页$first['p'] = 1;

$firstStr = http_build_query($first);

//处理尾页$end['p'] = $this->allPage;

$endStr = http_build_query($end);

$str = "共{$this->total}条数据 第{$this->current}/{$this->allPage}页 | ";

$str .= "首页| ";$str .= "上一页| ";$str .= "下一页| ";$str .= "尾页";

return $str;

    }

}

相关推荐:

php分页类实例详解

一款万能的php分页类实例代码

php分页类代码分享:2017年最新的10个php分页类代码下载

以上就是php基础分页类代码详解的详细内容,更多请关注php中文网其它相关文章!

 
关键词: php,详解,代码
 
[ 资讯搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 
0条 [查看全部]  相关评论

 
网站首页 | 关于我们 | 联系方式 | 使用协议 | 版权隐私 | 网站地图 | 排名推广 | 广告服务 | 积分换礼 | 网站留言 | RSS订阅 | 吉ICP备11001726号-6
企业800网 · 提供技术支持