标签:
<?php
class page
{
private $total; // 总记录数
private $nums;// 每页显示条数
private $pages;//总页数
private $cpage;//当前页
private $url;
public function __construct($total, $nums)
{
$this->total=$total;
$this->nums=$nums;
$this->pages=$this->getPage();
}
//总页数
private function getPage(){
return ceil($this->total/$this->nums);
}
//上一页
private function first(){
$this->cpage=!empty($_GET[‘page‘])?$_GET[‘page‘]:1;
if($this->cpage>1){
$pre=$this->cpage-1;
return ‘<a href="‘.$this->url.‘?page=1">首页</a><a href="‘.$this->url.‘?page=‘.$pre.‘">上一页</a>‘;
}
else {
return "";
}
}
//列表页
private function flist(){
$list="";
$num="4";
for($i=$num;$i>=1;$i--){
$page = $this->cpage - $i;
if($page > 1)
{
$list .= ‘ <a href="‘.$this->url.‘?page=‘.$page.‘">‘.$page.‘</a> ‘;
}
}
//当前页面
if($this->pages>1){
$list.=" {$this->cpage} ";
}
for($i=1;$i<$num;$i++){
$page=$this->cpage+$i;
if($page <= $this->pages)
{
$list .= ‘ <a href="‘.$this->url.‘?page=‘.$page.‘">‘.$page.‘</a> ‘;
}
else
{
break;
}
}
return $list;
}
//下一页
private function flast(){
if($this->pages>=$this->cpage){
$next=$this->cpage+1;
return ‘<a href="‘.$this->url.‘?page=‘.$next.‘">下一页</a><a href="‘.$this->url.‘?page=‘.$this->pages.‘">末页</a>‘;
}
}
public function fpage(){
return "总记录数 {$this->first()} {$this->flist()} {$this->flast()}" ;
}
}
标签:
原文地址:http://www.cnblogs.com/w84036937/p/4774074.html