Nov 14
一个php分页类,保存以备再研究...
学习
function geturl()
{
if(!empty($_SERVER['REQUEST_URI'])){
$scriptName = $_SERVER['REQUEST_URI'];
$nowurl = $scriptName;
}
else
{
$scriptName = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']=='')
$nowurl = $scriptName;
else
$nowurl = $scriptName.'?'.$_SERVER['QUERY_STRING'];
}
return $nowurl;
}
function ChangePage($pgSize,$pgCount,$cPage,$recCounts,$offNums,$showNums) {
$offset = $offNums;
if(empty($offNums)) {
$offset = 2;
}
$ShowPageNums = $showNums;
if(empty($showNums)) {
$showNums = 5;
}
$FromPage = ($cPage-$offset);
$ToPage = ($cPage+$ShowPageNums-$offset-1);
$strPage = '';
$returnString = '';
if($ShowPageNums>$pgCount) {
$FromPage = 1;
$ToPage = $pgCount;
}
$url = geturl();
$url = eregi_replace('((^|[&?])page='.$cPage.')','',$url);
if(!strpos($url,'?')) {
$url .= '?';
}
else {
$url .= '&';
}
if($FromPage<1) {
$ToPage = ($cPage+1-$FromPage);
$FromPage = 1;
if((($ToPage-$FromPage)<$ShowPageNums) && (($ToPage-$FromPage)<$pgCount)) {
$ToPage = $ShowPageNums;
}
}
else {
if($ToPage>$pgCount) {
$FromPage = ($cPage-$pgCount+$ToPage);
$ToPage = $pgCount;
if((($ToPage-$FromPage)<$ShowPageNums) && (($ToPage-$FromPage)<$pgCount)){
$FromPage = ($pgCount-$ShowPageNums+1);
}
}
}
for($i=$FromPage;$i<=$ToPage;$i++) {
if($i != $cPage) {
$strPage .= '['.$i.']';
}
else {
$strPage .= '['.$i.']';
}
}
//显示翻页数字
$returnString .= '
' .chr(13);
return $returnString;
}
{
if(!empty($_SERVER['REQUEST_URI'])){
$scriptName = $_SERVER['REQUEST_URI'];
$nowurl = $scriptName;
}
else
{
$scriptName = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']=='')
$nowurl = $scriptName;
else
$nowurl = $scriptName.'?'.$_SERVER['QUERY_STRING'];
}
return $nowurl;
}
function ChangePage($pgSize,$pgCount,$cPage,$recCounts,$offNums,$showNums) {
$offset = $offNums;
if(empty($offNums)) {
$offset = 2;
}
$ShowPageNums = $showNums;
if(empty($showNums)) {
$showNums = 5;
}
$FromPage = ($cPage-$offset);
$ToPage = ($cPage+$ShowPageNums-$offset-1);
$strPage = '';
$returnString = '';
if($ShowPageNums>$pgCount) {
$FromPage = 1;
$ToPage = $pgCount;
}
$url = geturl();
$url = eregi_replace('((^|[&?])page='.$cPage.')','',$url);
if(!strpos($url,'?')) {
$url .= '?';
}
else {
$url .= '&';
}
if($FromPage<1) {
$ToPage = ($cPage+1-$FromPage);
$FromPage = 1;
if((($ToPage-$FromPage)<$ShowPageNums) && (($ToPage-$FromPage)<$pgCount)) {
$ToPage = $ShowPageNums;
}
}
else {
if($ToPage>$pgCount) {
$FromPage = ($cPage-$pgCount+$ToPage);
$ToPage = $pgCount;
if((($ToPage-$FromPage)<$ShowPageNums) && (($ToPage-$FromPage)<$pgCount)){
$FromPage = ($pgCount-$ShowPageNums+1);
}
}
}
for($i=$FromPage;$i<=$ToPage;$i++) {
if($i != $cPage) {
$strPage .= '['.$i.']';
}
else {
$strPage .= '['.$i.']';
}
}
//显示翻页数字
$returnString .= '
| 共'.$recCounts.','.$pgSize.'条/页,共'.$pgCount.'页 | ' .chr(13);' .chr(13); if($cPage == 1) { $returnString .= '[首页]'; $returnString .= '[上页] '; } else { $returnString .= '[首页]'; $returnString .= '[上页] '; } $returnString .= $strPage .chr(13); if($cPage == $pgCount) { $returnString .= '[下页]'; $returnString .= '[尾页]'; } else { $returnString .= '[下页]'; $returnString .= '[尾页]'; } $returnString .= ''; $returnString .= ' | ' .chr(13);
return $returnString;
}
最新评论及回复