本文为大家分享个超级好用、万能的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 )
{