php 万能分页类,两款万能的php分页类_PHP

本文分享了两个实用的PHP分页类,包括详细的代码实现,适用于多种场景,有助于提升网页分页效果和用户体验。第一款类包含基本的分页功能,第二款类则提供更复杂的分页显示,如带总页数、跳转按钮等。
摘要由CSDN通过智能技术生成

本文为大家分享个超级好用、万能的php分页类,具体的实现代码如下

第一款php分页类

init(1000, 20);

* $page->setNotActiveTemplate('{a}');

* $page->setActiveTemplate('{a}');

* echo $page->show();

*

*

* @author 风居住的地方

*/

class Page {

/**

* 总条数

*/

private $total;

/**

* 每页大小

*/

private $pageSize;

/**

* 总页数

*/

private $pageNum;

/**

* 当前页

*/

private $page;

/**

* 地址

*/

private $uri;

/**

* 分页变量

*/

private $pageParam;

/**

* LIMIT XX,XX

*/

private $limit;

/**

* 数字分页显示

*/

private $listnum = 8;

/**

* 分页显示模板

* 可用变量参数

* {total} 总数据条数

* {pagesize} 每页显示条数

* {start} 本页开始条数

* {end} 本页结束条数

* {pagenum} 共有多少页

* {frist} 首页

* {pre}

* {last} 尾页

* {list} 数字分页

* {goto} 跳转按钮

*/

private $template = '

共有{total}条数据每页显示{pagesize}条数据,本页{start}-{end}条数据共有{pagenum}页{frist}{pre}{list}{next}{last}{goto}';

/**

* 当前选中的分页链接模板

*/

private $activeTemplate = '';

return $html;

}

/**

* 模板替换

* @param type $replace 替换内容

* @param type $result 条件

* @return type

*/

private function replace($url, $text, $result = true) {

$template = ($result ? $this->activeTemplate : $this->notActiveTemplate);

$html = str_replace('{url}', $url, $template);

$html = str_replace('{text}', $text, $html);

return $html;

}

}

第二款php分页类

page_num = ceil( $total / $this->length );

return $this->page_num;

}

function Calculation_Min_Max( $act_page = 1 )

{

// 定义左右偏移量

$py_left = 0;

$py_right = 0;

// 定义左右边界

$bj_left = 0;

$bj_right = 0;

// 定义滚动区间边界

$gd_left = 0;

$gd_right = 0;

// 判断是否需要分组

if ( ( $this->page_num - $this->page_max ) <= 0 )

{

// 不需要分组

$bj_left = 1;

$bj_right = $this->page_num;

}

else

{

// 要进行分组

// 判断容量的奇偶

$tmp = $this->page_max % 2;

if ( $tmp === 1 )

{

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值