php分页类:php分页类扩展

原来发表过个脱离数据库分页类最近使用时候发现有些时候搜索东西过于大时候采用url传递参数方式可能会有影响或者叫已知bug这次做了些扩展同时兼容了以前模式使用上面很简单只需要多设置个参数就可以了代码如下:

view plaincopy to clipboardpr?
<?php
/**
* 功能: 分页类根据提供数据总量和页面大小
* 创建日期:Fri Apr 20 16:45:21 CST 2007
* 最后更新:
* 作者: sanshi <[email protected]>
*/

pagination
{
var $result = .gif' />;
var $pVar = "myp";//page参数分页记数
var $urlParamStr = ""; //页面所有参数
var $sqlMoveNumber = 0; //数据偏移量
var $is_post = false;

public function pagination
{

}
public function ($sum,$pageSize,$page="",$is_post = false)
{
$this->is_post = $is_post;
$this->pVar = d('PAGE_BAR') ? PAGE_BAR : 'myp' ;
$url = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
//计算出总页数
$curPage = $this->getCurPage;

$temp['sumPage'] = ceil($sum/$pageSize);
//修改了,页码超出bug
($curPage>$temp['sumPage']) $curPage=$temp['sumPage'];
$temp['curPage'] = $curPage;
$temp['nextPage'] = $temp['sumPage'] > $curPage ? ($curPage+1) : $temp['sumPage'];
$temp['upPage'] = $curPage >1 ? $curPage-1 :1;
$temp['endPage'] = $temp['sumPage'];
$this->urlParamStr = $this->_makeUrl($url);
$temp['urlPageStr'] = ($page"") ? $this->_makeUrl($url) : $page.$this->urlParamStr;

$this->sqlMoveNumber = $curPage <2 ? 0 : ($curPage-1)*$pageSize;
$temp['sqlMoveNumber'] = $this->sqlMoveNumber;
$temp['rowNo'] = $sum;
$this->result = $temp;
$this->result;
//pr_r($temp);exit;
}
public function getSqlMove
{
$this->sqlMoveNumber;
}
public function getFooter
{
$str= "共有 <FONT COLOR=#FF0033>{$this->result['rowNo']}</FONT> 条 <a href='{$this->result['urlPageStr']}{$this->result['upPage']}'";
($this->is_post) $str .=" _disibledevent=>$str .=" >上页</a> ";
$str .=" 当前 {$this->result['curPage']} 页";
$str .=" 共有 {$this->result['sumPage']} 页";
$str .=" <a href='{$this->result['urlPageStr']}{$this->result['nextPage']}'";
($this->is_post) $str .=" _disibledevent=>$str .=" >下页</a>";
$str;
}
public function getJumpPage
{
($this->is_post)
{
$str = " 跳到第 <select name='topage' size='1' _disibledevent=>}{
$str = " 跳到第 <select name='topage' size='1' _disibledevent=>}
for($i=1;$i<=$this->result['sumPage'];$i)
{
$str .= ($i$this->result['curPage']) ? "<option value='$i' selected>$i</option>\n" : "<option value='$i'>$i</option>\n";
}
$str.="</select> 页";
//输出form表单
($this->is_post)
{
$str .="<mce:script type="text/javascript"><!--
function sanshi_page_post(jump_link,page_no)
{
document.getElementById('sanshi_goPage').action = jump_link; document.getElementById('{$this->pVar}').value = page_no;
document.getElementById('sanshi_goPage').submit;
false;
}

// --></mce:script>";
$str .="<form name='sanshi_goPage' id='sanshi_goPage' method=post>";
$str .="<input type=\"hidden\" name='{$this->pVar}' id='{$this->pVar}' value=0>";
$_POST = is($_POST) ? $_POST : .gif' />;
foreach($_POST AS $k=>$v)
{
$str .="<input type=\"hidden\" name=\"{$k}\" id=\"{$k}\" value=\"{$v}\">";
}
$str .="</form>";
}
$str;
}
public function getCurPage
{
is($_GET[$this->pVar]) ? val($_GET[$this->pVar]) : 1 ;
}
//分析出url参数返回?后参数页码为空 包括问号
private function _makeUrl($url)
{
$.gif' />Url=parse_url($url);
(is($.gif' />Url['query']))
{
$q=$.gif' />Url['query'];
parse_str($q,$qParam);
//pr_r($qParam);
(.gif' />_key_exists($this->pVar,$qParam))
{
foreach ($qParam AS $k=>$v)
{
($k !=$this->pVar) $temp[$k] = $v;
}
$temp[$this->pVar] = "";
(function_exists("http_build_query"))
'?'.http_build_query($temp);

'?'.sanshi_http_build_query($temp);
} {
"?{$q}&{$this->pVar}=";
}
}{
"?{$this->pVar}=";
}

}
}
function sanshi_http_build_query($a,$b='',$c=0)
{
(!is_.gif' />($a)) false;
foreach ((.gif' />)$a as $k=>$v)
{
($c)
$k=$b."[".$k."]";
(is_($k))
$k=$b.$k;
(is_.gif' />($v)||is_object($v))
{
$r=http_build_query($v,$k,1);
continue;
}
$r=$k."=".urlencode($v);
}
implode("&",$r);
}
/*
//pr_r($_SERVER);
$p = pagination;
$p->(10,2,'thi.php');
echo $p->getFooter;
echo $p->getJumpPage;
*/
?>
Tags:  php分页代码 php分页 php通用分页类 php分页类

延伸阅读

最新评论

发表评论