极光分页

<?
$pager0 = new arrPager(912,25);
$pager1 = new arrPager(912,25,5,"b");
$pager2 = new arrPager(912,25,9,"c");
echo $pager0->parse().'<br>';
echo $pager1->show().$pager1->parse().'<br>';
echo $pager2->show().$pager2->parse().$pager2->goto().'<br>';

/*
* 名称: 极光分页
*
* 作者: DCD QQ: 15972801 web开发群: 3574636
*
* 完成日期: 2006-4-19
*
* 版本:V1.05
*
* 特点:
*
* 一般情况下只要给这个类2个参数就能正常运行,使用很方便。
* URL中有其他变量时,也会自动加入相应的变量。
*
* 方法:
*
* arrPager arrPager(int intTotalDate, int intNumOfPage, [int intNumOfBar],[string strPageVar]);
* string show($a = '页次:', $b = '/', $c = ' 每页:', $d = ' 共计:')
* string parse()
*
* 属性:
*
* intTotalDate 总记录数
* intNumOfPage 每页显示记录数
* strPageVar 翻页变量名,默认为“PAGEID”
* intPageTotal 总页数
* intBeginDate 本页开始的记录序号
* intPage 当前页数
* intNumOfDate 当前页面显示的记录数
* intUpPage 上一页的页数
* intPageBegin 翻页条最开始的页数
*
*
* 1.04
* 版修复了一个致命BUG,防止从地址栏往网页里写入代码。
* 1.05
* 重新编写了大部分代码,修改变量名,与以前版本不兼容!
* 增加了show()方法,一般用来显示“页次:8/37 每页:25 共计:912”
*
*/
class arrPager {

/*
* 构造函数
*/
function arrPager($intTotalDate, $intNumOfPage, $intNumOfBar = 9, $strPageVar = 'PAGEID') {

$this->intTotalDate = $intTotalDate;
$this->intNumOfPage = $intNumOfPage;
$this->strPageVar = $strPageVar;
$this->intPageTotal = ceil($intTotalDate/$intNumOfPage);
//当前页数没有则为1
if (!isset($_GET[$this->strPageVar])) {
$_GET[$this->strPageVar] = 1;
}
//当前页数不允许超出最大页数
if ($_GET[$this->strPageVar] > $this->intPageTotal) {
$_GET[$this->strPageVar] = $this->intPageTotal;
}
//当前页数
$this->intPage = $_GET[$this->strPageVar];
//本页开始的记录序号
$this->intBeginDate = ($this->intPage - 1) * $this->intNumOfPage;
//本页显示记录数
if ($this->intPage == $this->intPageTotal) {
$this->intNumOfDate = $this->intPageTotal - ($this->intPage - 1) * $this->intNumOfPage;
}else {
$this->intNumOfDate = $this->intNumOfPage;
}
//上一页
if ($this->intPage <= 1){
$this->intUpPage = NULL;
}else {
$this->intUpPage = $this->intPage - 1;
}
//下一页
if ($this->intPage >= $this->intPageTotal){
$this->intPageDown = NULL;
}else {
$this->intPageDown = $this->intPage + 1;
}
//翻页条最开始的页数
if ($this->intPage <= ceil($intNumOfBar/2)){
$this->intPageBegin = 1;
}else {
$this->intPageBegin = $this->intPage - ceil($intNumOfBar/2 - 1);
}
//翻页条最后的页数
$this->intPageEnd = $this->intPageBegin + $intNumOfBar - 1;
if ($this->intPageEnd > $this->intPageTotal){
$this->intPageEnd = $this->intPageTotal;
$this->intPageBegin = $this->intPageTotal - $intNumOfBar + 1;
}
//地址栏
$this->get = $this->_get();
}

/*
* 解析辅助信息
*/
function show($a = '页次:', $b = '/', $c = ' 每页:', $d = ' 共计:') {
$out = $a.$this->intPage;
$out .= $b.$this->intPageTotal;
$out .= $c.$this->intNumOfPage;
$out .= $d.$this->intTotalDate."/r/n";
return $out;
}
/*
* 解析翻页条
*/
function parse(){
$out = '';
$out.= $this->_href(1,'<font face="webdings" color="red" title="First Page">9</font>')."/r/n";
$out.= $this->_href($this->intUpPage,'<font face="webdings" color="red" title="Prev Page">3</font>')."/r/n";
for ($i=$this->intPageBegin;$i<=$this->intPageEnd;$i++) {
$out.='['.$this->_href($i,$i).']'."/r/n";
}
$out.= $this->_href($this->intPageDown,'<font face="webdings" color="red" title="Next Page">4</font></a>')."/r/n";
$out.= $this->_href($this->intPageTotal,'<font face="webdings" color="red" title="Last Page">:</font>')."/r/n";
return $out;
}

/*
* 规范地址栏
*/
function _get() {
$out = '?';
foreach ($_GET as $key => $value){
if ($key == $this->strPageVar) {
continue;
}
$out .= $key.'='.htmlspecialchars($value).'&';
}
$out.=$this->strPageVar.'=';
return $out;
}
/*
* 链接样式
*/
function _href($num, $content){
if ($num == '') {
return $content;
}elseif ($num == $this->intPage AND $content == $this->intPage) {
return '<font color="#FF0000"><strong>'.$content.'</strong></font>';
}else {
return '<a href="'.$_SERVER["SCRIPT_NAME"].$this->get.$num.'">'.$content.'</a>';
}
}
/*
* 下拉菜单
*/
function goto() {
$out = '<select name="select" οnchange="javascript:window.location.href=this.options[this.selectedIndex].value">'."/r/n";
for ($i = 1;$i <= $this->intPageTotal;$i++){
$out .= $this->_option($i);
}
$out .= '</select>'."/r/n";
return $out;
}
function _option($num) {
if ($this->intPage == $num) {
$selected = ' selected';
}else {
$selected = '';
}
return '<option value="'.$_SERVER["SCRIPT_NAME"].$this->get.$num.'"'.$selected.'>第'.$num.'页</option>'."/r/n";
}


}//End Class
?> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值