PHP分页类集锦
本文汇集了几个比较好用的php分页类,都是经过广大网友考验的代码了,小伙伴们可以直接拿来使用
分页类一
复制代码 代码如下:
/**
分页类
修改: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 \"
\";
echo \"
*/
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 mIndexBarLength) {
$first_number = 1;
$last_number = $this->mTotalPagesNum;
} else {
$offset = ( int ) floor ( $this->mIndexBarLength / 2 );
if (($this->mCurPageNumber - $offset) $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 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 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() {
}
}
?>
分页类二
复制代码 代码如下:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
