<?php
/**
* 分页类
* Enter description here ...
* @author wf
*
*/
class SubPage{
private $total_num; //总记录条数
private $page_cur; //当前页
private $page_size; //每页显示记录条数
private $link; //相关的链接页面
private $page_flag; //页码标识
private $pramas; //其他参数
private $page_num; //显示的页数--总共
private $class; //链接的css类
/**
*
* Enter description here ...
* @param $total_num--记录总条数
* @param $page_size--分页大小(每页显示的数据条数)
* @param $link--数据链接地址
* @param $params--数据链接地址参数
*/
function __construct($total_num,$page_size,$page_cur,$link,$page_flag,$params){
$this->total_num = $total_num;
$this->page_size = $page_size;
$this->page_cur = $page_cur;
$this->link = $link;
$this->page_flag = $page_flag;
$this->pramas = $params;
$this->page_num = 5;
$this->class = 'pages';
}
function set_page_num($num){
$this->page_num = $num;
}
function set_page_class($class){
$this->class = $class;
}
/**
* 获取总页数
* Enter description here ...
*/
function get_total_page(){
return ceil($this->total_num/$this->page_size);
}
function get_page_url($page){
$url = $this->link.'?'.$this->page_flag.'='.$page.$this->pramas;
$cur = ($page==$this->page_cur)?$this->class.'_cur':'';
return "<a class='{$this->class} $cur' href='$url'>$page</a>";
}
//第一页
function get_first_page($desc='首页'){
$url = $this->link.'?'.$this->page_flag.'=1'.$this->pramas;
return "<a class='{$this->class}' href='$url'>$desc</a>";
}
//最末页
function get_last_page($desc='尾页'){
$url = $this->link.'?'.$this->page_flag.'='.$this->get_total_page().$this->pramas;
return "<a class='{$this->class}' href='$url'>$desc</a>";
}
function get_page_list(){
$page_cur = $this->page_cur;
$page_start = $page_cur - $this->page_num;
$page_start = $page_start>0?$page_start:1;
$page_end = $page_cur + $this->page_num;
$page_end = $page_end>$this->get_total_page()?$this->get_total_page():$page_end;
for($i=$page_start;$i<=$page_end;$i++){
$pages .= $this->get_page_url($i);
}
return $pages;
}
}
?>
/**
* 分页类
* Enter description here ...
* @author wf
*
*/
class SubPage{
private $total_num; //总记录条数
private $page_cur; //当前页
private $page_size; //每页显示记录条数
private $link; //相关的链接页面
private $page_flag; //页码标识
private $pramas; //其他参数
private $page_num; //显示的页数--总共
private $class; //链接的css类
/**
*
* Enter description here ...
* @param $total_num--记录总条数
* @param $page_size--分页大小(每页显示的数据条数)
* @param $link--数据链接地址
* @param $params--数据链接地址参数
*/
function __construct($total_num,$page_size,$page_cur,$link,$page_flag,$params){
$this->total_num = $total_num;
$this->page_size = $page_size;
$this->page_cur = $page_cur;
$this->link = $link;
$this->page_flag = $page_flag;
$this->pramas = $params;
$this->page_num = 5;
$this->class = 'pages';
}
function set_page_num($num){
$this->page_num = $num;
}
function set_page_class($class){
$this->class = $class;
}
/**
* 获取总页数
* Enter description here ...
*/
function get_total_page(){
return ceil($this->total_num/$this->page_size);
}
function get_page_url($page){
$url = $this->link.'?'.$this->page_flag.'='.$page.$this->pramas;
$cur = ($page==$this->page_cur)?$this->class.'_cur':'';
return "<a class='{$this->class} $cur' href='$url'>$page</a>";
}
//第一页
function get_first_page($desc='首页'){
$url = $this->link.'?'.$this->page_flag.'=1'.$this->pramas;
return "<a class='{$this->class}' href='$url'>$desc</a>";
}
//最末页
function get_last_page($desc='尾页'){
$url = $this->link.'?'.$this->page_flag.'='.$this->get_total_page().$this->pramas;
return "<a class='{$this->class}' href='$url'>$desc</a>";
}
function get_page_list(){
$page_cur = $this->page_cur;
$page_start = $page_cur - $this->page_num;
$page_start = $page_start>0?$page_start:1;
$page_end = $page_cur + $this->page_num;
$page_end = $page_end>$this->get_total_page()?$this->get_total_page():$page_end;
for($i=$page_start;$i<=$page_end;$i++){
$pages .= $this->get_page_url($i);
}
return $pages;
}
}
?>