45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:PHP分页类有什么?

PHP分页类有什么?

2016-09-01 10:38:17 来源:www.45fan.com 【

PHP分页类有什么?

新做的一个类,比较实用~~样式如下:

|<< << 1 2 3 4 5 6 7 8 >> >>|

大家觉得有用可以带走~~呵呵……

<?php

/***************************
* 一个非常实用个性的分页类 *
****************************

*****************************实例***********************************
if(!isset($_GET['page'])){$page = 0;}else{$page = $_GET['page'];}
$pagedemo = new pageclass;
$pagedemo->set_sql("SELECT * FROM `demo` ORDER BY `id` DESC");
$pagedemo->set_params("type=".$type."");
$pagedemo->set_setpage($page);
$pagedemo->set_pagesize(10);
$pagedemo->set_filename("demo.php");
$pagedemo->set_pagenumber(5);
$pagedemo->show();
$result=$pagedemo->result;
$n=0;
while ($row=mysql_fetch_row($result)){
$n++;
echo "内容";
}
$pagedemo->showpage();
*******************************************************************/

class pageclass
{
/****声明****/
var $sqlstr,$filename,$params,$initfirstpage;
var $pagestart,$pagenumber,$pagesize,$i;
var $firstpage,$prevpage,$nextpage,$lastpage;
var $totallines,$maxpage,$totalpages,$result;
var $page,$final,$getpage,$param,$paramlist;

/****构造函数****/
function pageclass()
{
$this->set_initfirstpage("仅此一页"); // 设置只有一页时显示的文字;
$this->set_setpage(0); // 设置默认第一页为0;
$this->set_pagesize(10); // 设置默认记录数为10;
$this->set_params(""); // 设置默认参数列表为空;
$this->set_pagestart(0); // 设置默认分页起始数为0;
$this->set_pagenumber(5); // 设置默认每页显示页数为5;
$this->set_firstpage("|<<"); // 设置默认上N页表示字符为|<<;
$this->set_prevpage("<<"); // 设置默认上一页表示字符为<<;
$this->set_nextpage(">>"); // 设置默认下一页表示字符为>>;
$this->set_lastpage(">>|"); // 设置默认下N页表示字符为>>|;
}

/*****设置SQL查询语句****/
function set_sql($sqlstr)
{
$this->sqlstr = $sqlstr;
}

/****设置每页显示记录数****/
function set_pagesize($pagesize)
{
$this->pagesize = $pagesize;
}

/****设置文件名称****/
function set_filename($filename)
{
$this->filename = $filename;
}

/****设置参数列表(可设多项)****/
function set_params($params)
{
$this->params = $params;
}

/****设置页面开始数(默认为0)****/
function set_pagestart($pagestart)
{
$this->pagestart = $pagestart;
}

/****设置每页显示页数****/
function set_pagenumber($pagenumber)
{
$this->pagenumber = $pagenumber;
}

/****设置首页图标或字符****/
function set_firstpage($firstpage)
{
$this->firstpage = $firstpage;
}

/****设置上一页图标或字符****/
function set_prevpage($prevpage)
{
$this->prevpage = $prevpage;
}

/****设置下一页图标或字符****/
function set_nextpage($nextpage)
{
$this->nextpage = $nextpage;
}

/****设置末页图标或字符****/
function set_lastpage($lastpage)
{
$this->lastpage = $lastpage;
}

/****设置总页数为一页时显示的文字****/
function set_initfirstpage($initfirstpage)
{
$this->initfirstpage = $initfirstpage;
}

/****取得当前页数****/
function set_setpage($getpage)
{
$this->getpage = $getpage;
}

/****取出数据集****/
function show()
{
$this->final = '';
$this->param = preg_replace("/&?page=[0-9]*&?/", '', $this->params);
$this->totallines = mysql_num_rows(mysql_query($this->sqlstr));
if(isset($this->totallines))
{
$this->totalpages = ceil($this->totallines / $this->pagesize);
}else{
$this->totalpages = 1;
}
$this->result = mysql_query($this->sqlstr." limit ".$this->getpage * $this->pagesize .", ". $this->pagesize);
}

/****显示分页****/
function showpage()
{
if($this->totalpages > $this->pagenumber && $this->getpage > $this->pagenumber - 1)
{
$this->paramlist = '?page='.($this->getpage - $this->pagenumber);
$this->paramlist .= "&".$this->param;
$this->final .= "<a href=./".$this->filename.$this->paramlist.">".$this->firstpage."</a> ";
$this->pagestart = intval($this->getpage / $this->pagenumber) * $this->pagenumber;
}else $this->final .= $this->firstpage." ";
if($this->getpage)
{
$this->paramlist = '?page='.($this->getpage - 1);
$this->paramlist .= "&".$this->param;
$this->final .= "<a href=./".$this->filename.$this->paramlist.">".$this->prevpage."</a> ";
} else $this->final .= $this->prevpage." ";
if($this->totalpages < $this->pagenumber)
{
$this->maxpage = $this->totalpages;
}else{
$this->maxpage = $this->pagenumber;
}
for($this->i = $this->pagestart, $this->paramlist = '', $this->maxpage += $this->pagestart; $this->i < $this->maxpage; $this->i ++) {
$this->paramlist .= '?page='.$this->i;
$this->paramlist .= "&".$this->param;
if($this->i != $this->getpage)
{
$this->final .= "<a href=./".$this->filename.$this->paramlist.">".($this->i + 1).'</a> ';
}else{
$this->final .= "<a href=./".$this->filename.$this->paramlist."><strong>".($this->i + 1).'</strong></a> ';
}
$this->paramlist = '';
}
if((++ $this->getpage)< $this->totalpages)
{
$this->paramlist = "?page=".$this->getpage;
$this->paramlist .= "&".$this->param;
$this->final .= "<a href=./".$this->filename.$this->paramlist.">".$this->nextpage."</a> ";
} else $this->final .= " ".$this->nextpage;
$this->getpage --;
if(($this->getpage + $this->pagenumber) < $this->totalpages)
{
$this->paramlist = '?page='.($this->getpage + $this->pagenumber);
$this->paramlist .= "&".$this->param;
$this->final .= " <a href=./".$this->filename.$this->paramlist.">".$this->lastpage."</a>";
} else $this->final .= " ".$this->lastpage;
if($this->maxpage == 1) $this->final = $this->initfirstpage;
print $this->final;
}

}

?>

 

本文地址:http://www.45fan.com/a/question/70728.html
Tags: 一个 PHP 新做
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部