PHP分页类集锦_php实例_脚本之家

2020-01-31 14:40栏目:bob体育平台
TAG:

分页类一

分页类一

这个类适用于配合数据库教程查询分页,和数组分页。下面有使用方法。
[php教程]
<?php
/*
* 名称: 分页类
* 介绍: 适用于数组分页和配合sql查询的分页
* 作者: idlion || moonfly (id_lion@hotmail.com)
* 创建时间: 2006-02-18
* 最后修改: 2007-05-24
*/

复制代码 代码如下:GetIndexBar () . $page->GetPageInfo (); print_r ; echo "

复制代码 代码如下:
/**
分页类
修改:Silence
Creatdate:2006-5-30
LastModify:2009-5-31
使用方法
$page = new page ( $result, 20 ); //$result为返回记录集数组 ,20为返回每页条数
$index = $page->GetIndexBar () . $page->GetPageInfo ();
print_r ( $result );
echo "

class pagebreak {
private $mtotalrowsnum = 0;   // 总信息行数
private $mcurpagenumber = 1;  // 当前所在页
private $mtotalpagesnum = 1;  // 总页数
private $mquerystring;     // 页面传递的数据(url?后的字符串)
private $mpagerowsnum = 20;  // 每页显示行数
private $mindexbarlength = 5;  // 索引条的页数
private $mindexbar = '';     // 页码索引条
private $mpageinfo = '';     // 分页信息
// 页码索引条样式
private $mnextbutton = "<font style="font-family:webdings">8</font>";
private $mprebutton = "<font style="font-family:webdings">7</font>";
private $mfirstbutton = "<font style="font-family:webdings">9</font>";
private $mlastbutton = "<font style="font-family:webdings">:</font>";
private $mcss教程indexbarcurpage = "font-weight:bold;color:#ff0000";
private $mcssindexbarpage = '';
// 分页信息样式
private $mcsspageinfonumfont = 'color:#ff0000';
private $mcsspageinfofont = '';

// 构造方法
public function __construct(&$rsqlquery, $userpagerowsnum='') {
  if( !is_array($rsqlquery) ) {
   $this->setdbpagebreak($rsqlquery, $userpagerowsnum);
  }
  else {
   $this->setarraypagebreak($rsqlquery, $userpagerowsnum);
  }
}

// 设置数据库型分页
private function setdbpagebreak(&$rsqlquery, $userpagerowsnum='') {
  $this->setdbtotalrowsnum($rsqlquery);
  $this->settotalpagesnum($userpagerowsnum);
  if( $this->mtotalpagesnum > 1 ) {
   $this->setcurpagenumber();
   $this->setsqlquery($rsqlquery);
   $this->setquerystring();
   $this->setindexbar();
   $this->setpageinfo();
  }
}

// 设置数组型分页
private function setarraypagebreak(&$rarray, $userpagerowsnum='', $usertotalrowsnum='') {
  $this->setarraytotalrowsnum($rarray, $usertotalrowsnum);
  $this->settotalpagesnum($userpagerowsnum);
  if( $this->mtotalpagesnum > 1 ) {
   $this->setcurpagenumber();
   $this->setarray($rarray);
   $this->setquerystring();
   $this->setindexbar();
   $this->setpageinfo();
  }
}

// 数据库型计算总行数
private function setdbtotalrowsnum($rsqlquery) {
  $this->mtotalrowsnum = mysql教程_num_rows( mysql_query($rsqlquery) );
}

// 数组型计算总行数
private function setarraytotalrowsnum($array) {
  $this->mtotalrowsnum = count($array);
}

// 计算总页数
private function settotalpagesnum($userpagerowsnum='') {
  if( $userpagerowsnum ) {
   $this->mpagerowsnum = $userpagerowsnum;
  }
  $this->mtotalpagesnum = (int)( floor( ($this->mtotalrowsnum-1)/$this->mpagerowsnum )+1 );
}

// 计算当前页数
private function setcurpagenumber() {
  if( $_get['cur_page'] ) {
   $this->mcurpagenumber = $_get['cur_page'];
  }
}

// 修正sql截取语句
private function setsqlquery(&$rsqlquery) {
  $start_number = ($this->mcurpagenumber-1)*$this->mpagerowsnum;
  $rsqlquery .= " limit ".$start_number.",".$this->mpagerowsnum;
}

// 修正截取后的array
private function setarray(&$rarray) {
  $start_number = ($this->mcurpagenumber-1)*$this->mpagerowsnum;
  $rarray = array_slice($rarray, $start_number, $this->mpagerowsnum);
}

// 修正 $_get 传递数据
private function setquerystring() {
  $query_string = $_server['query_string'];
  if ( $query_string == '' ) {
   $this->mquerystring = "?cur_page=";
  }
  else {
   $this->mquerystring = preg_replace("/&?cur_page=d+/", '', $query_string);
   $this->mquerystring = "?".$this->mquerystring."&cur_page=";
  }
}

// 设置页码索引条
private function getpageindex() {
  if( $this->mtotalpagesnum <= $this->mindexbarlength ) {
   $first_number = 1;
   $last_number = $this->mtotalpagesnum;
  }
  else {
   $offset = (int)floor($this->mindexbarlength/2);
   if( ($this->mcurpagenumber-$offset) <= 1 ) {
    $first_number = 1;
   }
   elseif( ($this->mcurpagenumber+$offset) > $this->mtotalpagesnum ) {
    $first_number = $this->mtotalpagesnum-$this->mindexbarlength+1;
   }
   else {
    $first_number = $this->mcurpagenumber-$offset;
   }
   $last_number = $first_number+$this->mindexbarlength-1;
  }
  $last_number;
  for( $i=$first_number; $i<=$last_number; $i++ ) {
   if( $this->mcurpagenumber == $i ) {
    $page_index .= "<font style='".$this->mcssindexbarcurpage."'>".$i."</font> ";
   }
   else {
    $page_index .= "<a href='".$this->mquerystring.$i."' style='".$this->mcssindexbarpage."'>".$i."</a> ";
   }
  }
  return $page_index;
}

// 设置页码索引条
private function setindexbar() {
  $this->mindexbar = $this->getnavfirstbutton();
  $this->mindexbar .= $this->getnavprebutton();
  $this->mindexbar .= $this->getpageindex();
  $this->mindexbar .= $this->getnavnextbutton();
  $this->mindexbar .= $this->getnavlastbutton();
}

// 得到页码索引条 首页按钮
private function getnavfirstbutton() {
  return "<a href='".$this->mquerystring."1'>".$this->mfirstbutton."</a> ";
}

// 得到页码索引条 上一页按钮
private function getnavprebutton() {
  if( $this->mcurpagenumber>1 ) {
   $pre_number = $this->mcurpagenumber-1;
  }
  else {
   $pre_number = 1;
  }
  return "<a href='".$this->mquerystring.$pre_number."'>".$this->mprebutton."</a> ";
}

// 得到页码索引条 下一页按钮
private function getnavnextbutton() {
  if( $this->mcurpagenumber<$this->mtotalpagesnum ) {
   $next_number = $this->mcurpagenumber+1;
  }
  else {
   $next_number = $this->mtotalpagesnum;
  }
  return "<a href='".$this->mquerystring.$next_number."'>".$this->mnextbutton."</a> ";
}

// 得到页码索引条 末页按钮
private function getnavlastbutton() {
  return "<a href='".$this->mquerystring.$this->mtotalpagesnum."'>".$this->mlastbutton."</a> ";
}

// 设置分页信息
private function setpageinfo() {
  $this->mpageinfo ="<font style='".$this->mcsspageinfofont."'>";
  $this->mpageinfo .= "共 <font style='".$this->mcsspageinfonumfont."'>".$this->mtotalrowsnum."</font> 条信息 | ";
  $this->mpageinfo .= "<font style='".$this->mcsspageinfonumfont."'>".$this->mpagerowsnum."</font> 条/页 | ";
  $this->mpageinfo .= "共 <font style='".$this->mcsspageinfonumfont."'>".$this->mtotalpagesnum."</font> 页 | ";
  $this->mpageinfo .= "第 <font style='".$this->mcsspageinfonumfont."'>".$this->mcurpagenumber."</font> 页";
  $this->mpageinfo .= "</font>";
}

// 取出页码索引条
public function getindexbar() {
  return $this->mindexbar;
}

// 取出分页信息
public function getpageinfo() {
  return $this->mpageinfo;
}

}
?>
[/php]

"; echo "".$index."";*/class Page { private $mTotalRowsNum = 0; // 总信息行数 private $mCurPageNumber = 1; // 当前所在页 private $mTotalPagesNum = 1; // 总页数 private $mQueryString; // 页面传递的数据 private $mPageRowsNum = 20; // 每页显示行数 private $mIndexBarLength = 11; // 索引条的页数 private $mIndexBar = ''; // 页码索引条 private $mPageInfo = ''; // 分页信息 // 页码索引条样式 private $mNextButton = "8"; private $mPreButton = "7"; private $mFirstButton = "9"; private $mLastButton = ":"; private $mCssIndexBarCurPage = "font-weight:bold;color:#FF0000"; private $mCssIndexBarPage = ''; // 分页信息样式 private $mCssPageInfoNumFont = 'color:#FF0000'; private $mCssPageInfoFont = ''; // 构造方法 public function __construct(&$rSqlQuery, $userPageRowsNum = '') { if (! is_array { $this->SetDbPageBreak ( $rSqlQuery, $userPageRowsNum ); } else { $this->SetArrayPageBreak ( $rSqlQuery, $userPageRowsNum ); } } // 设置数据库型分页 private function SetDbPageBreak(&$rSqlQuery, $userPageRowsNum = '') { $this->SetDbTotalRowsNum ; $this->SetTotalPagesNum ; if ($this->mTotalPagesNum > 1) { $this->SetCurPageNumber (); $this->SetSqlQuery ; $this->SetQueryString (); $this->SetIndexBar (); $this->SetPageInfo (); } } // 设置数组型分页 private function SetArrayPageBreak(&$rArray, $userPageRowsNum = '', $userTotalRowsNum = '') { $this->SetArrayTotalRowsNum ( $rArray, $userTotalRowsNum ); $this->SetTotalPagesNum ; if ($this->mTotalPagesNum > 1) { $this->SetCurPageNumber (); $this->SetArray ; $this->SetQueryString (); $this->SetIndexBar (); $this->SetPageInfo (); } } // 数据库型计算总行数 private function SetDbTotalRowsNum { $this->mTotalRowsNum = mysql_num_rows ( mysql_query ; } // 数组型计算总行数 private function SetArrayTotalRowsNum { $this->mTotalRowsNum = count ; } // 计算总页数 private function SetTotalPagesNum($userPageRowsNum = '') { if { $this->mPageRowsNum = $userPageRowsNum; } $this->mTotalPagesNum = (floor ( ($this->mTotalRowsNum - 1) / $this->mPageRowsNum ) + 1); } // 计算当前页数 private function SetCurPageNumber() { if { $this->mCurPageNumber = $_GET ['page']; } } // 修正Sql截取语句 private function SetSqlQuery { $start_number = ($this->mCurPageNumber - 1) * $this->mPageRowsNum; $rSqlQuery .= " LIMIT " . $start_number . "," . $this->mPageRowsNum; } // 修正截取后的Array private function SetArray { $start_number = ($this->mCurPageNumber - 1) * $this->mPageRowsNum; $rArray = array_slice ( $rArray, $start_number, $this->mPageRowsNum ); } // 修正 $_GET 传递数据 private function SetQueryString() { $query_string = $_SERVER ['QUERY_STRING']; if { $this->mQueryString = "?page="; } else { $this->mQueryString = preg_replace ( "/&?page=d+/", '', $query_string ); $this->mQueryString = "?" . $this->mQueryString . "&page="; } } // 设置页码索引条 private function GetPageIndex() { if ($this->mTotalPagesNum <= $this->mIndexBarLength) { $first_number = 1; $last_number = $this->mTotalPagesNum; } else { $offset = floor ( $this->mIndexBarLength / 2 ); if (($this->mCurPageNumber - $offset) <= 1) { $first_number = 1; } elseif (($this->mCurPageNumber + $offset) > $this->mTotalPagesNum) { $first_number = $this->mTotalPagesNum - $this->mIndexBarLength + 1; } else { $first_number = $this->mCurPageNumber - $offset; } $last_number = $first_number + $this->mIndexBarLength - 1; } $last_number; for($i = $first_number; $i <= $last_number; $i ++) { if ($this->mCurPageNumber == $i) { $page_index .= "" . $i . " "; } else { $page_index .= " " . $i . " "; } } return $page_index; } // 设置页码索引条 private function SetIndexBar() { $this->mIndexBar = $this->GetNavFirstButton (); $this->mIndexBar .= $this->GetNavPreButton (); $this->mIndexBar .= $this->GetPageIndex (); $this->mIndexBar .= $this->GetNavNextButton (); $this->mIndexBar .= $this->GetNavLastButton (); } // 得到页码索引条 首页按钮 private function GetNavFirstButton() { return "https://www.jb51.net/article/" . $this->mFirstButton . " "; } // 得到页码索引条 上一页按钮 private function GetNavPreButton() { if ($this->mCurPageNumber > 1) { $pre_number = $this->mCurPageNumber - 1; } else { $pre_number = 1; } return "https://www.jb51.net/article/" . $this->mPreButton . " "; } // 得到页码索引条 下一页按钮 private function GetNavNextButton() { if ($this->mCurPageNumber < $this->mTotalPagesNum) { $next_number = $this->mCurPageNumber + 1; } else { $next_number = $this->mTotalPagesNum; } return "https://www.jb51.net/article/" . $this->mNextButton . " "; } // 得到页码索引条 末页按钮 private function GetNavLastButton() { return "https://www.jb51.net/article/" . $this->mLastButton . " "; } // 设置分页信息 private function SetPageInfo() { $this->mPageInfo = ""; $this->mPageInfo .= "共 " . $this->mTotalRowsNum . " 条信息 | "; $this->mPageInfo .= "" . $this->mPageRowsNum . " 条/页 | "; $this->mPageInfo .= "共 " . $this->mTotalPagesNum . " 页 | "; $this->mPageInfo .= "第 " . $this->mCurPageNumber . " 页"; $this->mPageInfo .= ""; } // 取出页码索引条 public function GetIndexBar() { return $this->mIndexBar; } // 取出分页信息 public function GetPageInfo() { return $this->mPageInfo; } //释放类 function __destruct() { } } ?>

";
echo "

 

分页类二

".$index."

用法1: 配合数据库使用(例子中配合的是我自己的数据库操作类和模版类)

复制代码 代码如下:".($totle?."-".min($firstcount+$displaypg,$totle)." 条记录,共 $totle 条记录";//如果只有一页则跳出函数:if return false;$pagenav.=" 首页 ";if $pagenav.=" 前页 "; else $pagenav.=" 前页 ";if $pagenav.=" 后页 "; else $pagenav.=" 后页 ";$pagenav.=" 尾页 ";//下拉跳转列表,循环列出所有页码:$pagenav.=" 到第 n";for($i=1;$i<=$lastpg;$i++){if $pagenav.="$in";else $pagenav.="$in";}$pagenav.=" 页,共 $lastpg 页";}}

";
*/
class Page {
private $mTotalRowsNum = 0; // 总信息行数
private $mCurPageNumber = 1; // 当前所在页
private $mTotalPagesNum = 1; // 总页数
private $mQueryString; // 页面传递的数据(url?后的字符串)
private $mPageRowsNum = 20; // 每页显示行数
private $mIndexBarLength = 11; // 索引条的页数
private $mIndexBar = ''; // 页码索引条
private $mPageInfo = ''; // 分页信息
// 页码索引条样式
private $mNextButton = "8";
private $mPreButton = "7";
private $mFirstButton = "9";
private $mLastButton = ":";
private $mCssIndexBarCurPage = "font-weight:bold;color:#FF0000";
private $mCssIndexBarPage = '';
// 分页信息样式
private $mCssPageInfoNumFont = 'color:#FF0000';
private $mCssPageInfoFont = '';
// 构造方法
public function __construct(&$rSqlQuery, $userPageRowsNum = '') {
if (! is_array ( $rSqlQuery )) {
$this->SetDbPageBreak ( $rSqlQuery, $userPageRowsNum );
} else {
$this->SetArrayPageBreak ( $rSqlQuery, $userPageRowsNum );
}
}
// 设置数据库型分页
private function SetDbPageBreak(&$rSqlQuery, $userPageRowsNum = '') {
$this->SetDbTotalRowsNum ( $rSqlQuery );
$this->SetTotalPagesNum ( $userPageRowsNum );
if ($this->mTotalPagesNum > 1) {
$this->SetCurPageNumber ();
$this->SetSqlQuery ( $rSqlQuery );
$this->SetQueryString ();
$this->SetIndexBar ();
$this->SetPageInfo ();
}
}
// 设置数组型分页
private function SetArrayPageBreak(&$rArray, $userPageRowsNum = '', $userTotalRowsNum = '') {
$this->SetArrayTotalRowsNum ( $rArray, $userTotalRowsNum );
$this->SetTotalPagesNum ( $userPageRowsNum );
if ($this->mTotalPagesNum > 1) {
$this->SetCurPageNumber ();
$this->SetArray ( $rArray );
$this->SetQueryString ();
$this->SetIndexBar ();
$this->SetPageInfo ();
}
}
// 数据库型计算总行数
private function SetDbTotalRowsNum($rSqlQuery) {
$this->mTotalRowsNum = mysql_num_rows ( mysql_query ( $rSqlQuery ) );
}
// 数组型计算总行数
private function SetArrayTotalRowsNum($array) {
$this->mTotalRowsNum = count ( $array );
}
// 计算总页数
private function SetTotalPagesNum($userPageRowsNum = '') {
if ($userPageRowsNum) {
$this->mPageRowsNum = $userPageRowsNum;
}
$this->mTotalPagesNum = ( int ) (floor ( ($this->mTotalRowsNum - 1) / $this->mPageRowsNum ) + 1);
}
// 计算当前页数
private function SetCurPageNumber() {
if ($_GET ['page']) {
$this->mCurPageNumber = $_GET ['page'];
}
}
// 修正Sql截取语句
private function SetSqlQuery(&$rSqlQuery) {
$start_number = ($this->mCurPageNumber - 1) * $this->mPageRowsNum;
$rSqlQuery .= " LIMIT " . $start_number . "," . $this->mPageRowsNum;
}
// 修正截取后的Array
private function SetArray(&$rArray) {
$start_number = ($this->mCurPageNumber - 1) * $this->mPageRowsNum;
$rArray = array_slice ( $rArray, $start_number, $this->mPageRowsNum );
}
// 修正 $_GET 传递数据
private function SetQueryString() {
$query_string = $_SERVER ['QUERY_STRING'];
if ($query_string == '') {
$this->mQueryString = "?page=";
} else {
$this->mQueryString = preg_replace ( "/&?page=d+/", '', $query_string );
$this->mQueryString = "?" . $this->mQueryString . "&page=";
}
}
// 设置页码索引条
private function GetPageIndex() {
if ($this->mTotalPagesNum <= $this->mIndexBarLength) {
$first_number = 1;
$last_number = $this->mTotalPagesNum;
} else {
$offset = ( int ) floor ( $this->mIndexBarLength / 2 );
if (($this->mCurPageNumber - $offset) <= 1) {
$first_number = 1;
} elseif (($this->mCurPageNumber + $offset) > $this->mTotalPagesNum) {
$first_number = $this->mTotalPagesNum - $this->mIndexBarLength + 1;
} else {
$first_number = $this->mCurPageNumber - $offset;
}
$last_number = $first_number + $this->mIndexBarLength - 1;
}
$last_number;
for($i = $first_number; $i <= $last_number; $i ++) {
if ($this->mCurPageNumber == $i) {
$page_index .= "" . $i . " ";
} else {
$page_index .= " " . $i . " ";
}
}
return $page_index;
}
// 设置页码索引条
private function SetIndexBar() {
$this->mIndexBar = $this->GetNavFirstButton ();
$this->mIndexBar .= $this->GetNavPreButton ();
$this->mIndexBar .= $this->GetPageIndex ();
$this->mIndexBar .= $this->GetNavNextButton ();
$this->mIndexBar .= $this->GetNavLastButton ();
}
// 得到页码索引条 首页按钮
private function GetNavFirstButton() {
return "" . $this->mFirstButton . " ";
}
// 得到页码索引条 上一页按钮
private function GetNavPreButton() {
if ($this->mCurPageNumber > 1) {
$pre_number = $this->mCurPageNumber - 1;
} else {
$pre_number = 1;
}
return "" . $this->mPreButton . " ";
}
// 得到页码索引条 下一页按钮
private function GetNavNextButton() {
if ($this->mCurPageNumber < $this->mTotalPagesNum) {
$next_number = $this->mCurPageNumber + 1;
} else {
$next_number = $this->mTotalPagesNum;
}
return "" . $this->mNextButton . " ";
}
// 得到页码索引条 末页按钮
private function GetNavLastButton() {
return "" . $this->mLastButton . " ";
}
// 设置分页信息
private function SetPageInfo() {
$this->mPageInfo = "";
$this->mPageInfo .= "共 " . $this->mTotalRowsNum . " 条信息 | ";
$this->mPageInfo .= "" . $this->mPageRowsNum . " 条/页 | ";
$this->mPageInfo .= "共 " . $this->mTotalPagesNum . " 页 | ";
$this->mPageInfo .= "第 " . $this->mCurPageNumber . " 页";
$this->mPageInfo .= "";
}
// 取出页码索引条
public function GetIndexBar() {
return $this->mIndexBar;
}
// 取出分页信息
public function GetPageInfo() {
return $this->mPageInfo;
}
//释放类
function __destruct() {
}
}
?>

// 这是一个sql查询语句,我们来对它的查询结果作出分页
$sql = "select * from member";

//-------------------------具体演示举例-------------------------------/*//include; //包含“pageft.php”文件//取得总信息数$result=mysql_query("select * from mytable");$total=mysql_num_rows,每页显示10条信息,使用本页URL。pageft;//现在产生的全局变量就派上用场了:$result=mysql_query("select * from mytable limit $firstcount,$displaypg ");while($row=mysql_fetch_array}//输出分页导航条代码:echo $pagenav;//*/?>

分页类二

// 读取分页类
require_once("pagebreak.php");

分页类系列之三

复制代码 代码如下:
/*
* Created on 2007-6-8
* Programmer : Alan , Msn - haowubai@hotmail.com
* KeBeKe.com Develop a project PHP - MySQL - Apache
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
//为了避免重复包含文件而造成错误,加了判断函数是否存在的条件:
if(!function_exists(pageft)){
//定义函数pageft(),三个参数的含义为:
//$totle:信息总数;
//$displaypg:每页显示信息数,这里设置为默认是20;
//$url:分页导航中的链接,除了加入不同的查询信息“page”外的部分都与这个URL相同。
//   默认值本该设为本页URL(即$_SERVER["REQUEST_URI"]),但设置默认值的右边只能为常量,所以该默认值设为空字符串,在函数内部再设置为本页URL。
function pageft($totle,$displaypg=20,$url=''){
//定义几个全局变量:
//$page:当前页码;
//$firstcount:(数据库)查询的起始项;
//$pagenav:页面导航条代码,函数内部并没有将它输出;
//$_SERVER:读取本页URL“$_SERVER["REQUEST_URI"]”所必须。
global $page,$firstcount,$pagenav,$_SERVER;
//为使函数外部可以访问这里的“$displaypg”,将它也设为全局变量。注意一个变量重新定义为全局变量后,原值被覆盖,所以这里给它重新赋值。
$GLOBALS["displaypg"]=$displaypg;
if(!$page) $page=1;
//如果$url使用默认,即空值,则赋值为本页URL:
if(!$url){ $url=$_SERVER["REQUEST_URI"];}
//URL分析:
$parse_url=parse_url($url);
$url_query=$parse_url["query"]; //单独取出URL的查询字串
if($url_query){
//因为URL中可能包含了页码信息,我们要把它去掉,以便加入新的页码信息。
//这里用到了正则表达式,请参考“PHP中的正规表达式”
$url_query=ereg_replace("(^|&)page=$page","",$url_query);
//将处理后的URL的查询字串替换原来的URL的查询字串:
$url=str_replace($parse_url["query"],$url_query,$url);
//在URL后加page查询信息,但待赋值:
if($url_query) $url.="&page"; else $url.="page";
}else {
$url.="?page";
}
//页码计算:
$lastpg=ceil($totle/$displaypg); //最后页,也是总页数
$page=min($lastpg,$page);
$prepg=$page-1; //上一页
$nextpg=($page==$lastpg ? 0 : $page+1); //下一页
$firstcount=($page-1)*$displaypg;
//开始分页导航条代码:
$pagenav="显示第 ".($totle?($firstcount+1):0)."-".min($firstcount+$displaypg,$totle)." 条记录,共 $totle 条记录";
//如果只有一页则跳出函数:
if($lastpg<=1) return false;
$pagenav.=" 首页 ";
if($prepg) $pagenav.=" 前页 "; else $pagenav.=" 前页 ";
if($nextpg) $pagenav.=" 后页 "; else $pagenav.=" 后页 ";
$pagenav.=" 尾页 ";
//下拉跳转列表,循环列出所有页码:
$pagenav.=" 到第 n";
for($i=1;$i<=$lastpg;$i++){
if($i==$page) $pagenav.="$in";
else $pagenav.="$in";
}
$pagenav.=" 页,共 $lastpg 页";
}
}

// 分页初始化
// $sql就是上面的查询语句
// 20是每页显示的数量
// 通过分页类的初始化,这个查询语句就被加上" limit ...... "
$pagebreak = new pagebreak($sql, 20);

版权声明:本文由bob体育app发布于bob体育平台,转载请注明出处:PHP分页类集锦_php实例_脚本之家