收集了三个PHP分页方法,总会有一个适合你用的。
方法一:
复制代码 代码如下:
/*
分页类 用于实现对多条数据分页显示
version:1.0
Date:2013-10-20
*/
/*
调用非常方便,先连接好数据库,直接传人查询的sql字符串即可,也可以指定每页显示的数据条数
例如$pages = new Page('SELECT * FROM `zy_common_member`');
或 $pages = new Page('SELECT * FROM `zy_common_member`', 10);
*/
class Page{
private $curPage;
private $totalPages;//数据总共分多少页显示
private $dispNum;//每页显示的数据条数
private $queryStr;//查询的SQL语句
private $limitStr;//查询语句后面的limit控制语句
/*
构造函数
$queryStr 查询数据的SQL语句
$dispNum 每页显示的数据条数
*/
public function __construct($queryStr='',$dispNum=10){
$result = mysql_query($queryStr);
$totalNum = mysql_num_rows($result);
$this->dispNum = $dispNum;
$this->totalPages = ceil($totalNum / $dispNum);
$this->queryStr = $queryStr;
$temp = (isset($_GET["curPage"]) ? $_GET["curPage"] : 1);
$this->setCurPage($temp);
$this->showCurPage();
$this->showFoot();
}
/*显示当前页的数据内容*/
private function showCurPage(){
$this->limitStr = ' LIMIT '.(($this->curPage - 1)* $this->dispNum).','.$this->dispNum;
//echo $this->queryStr.$this->limitStr;
$result = mysql_query($this->queryStr.$this->limitStr);
if (!$result)
{
if ($this->totalPages > 0)
{
echo '查询出错'.'
';
}
else
{
echo '无数据'.'
';
}
return;
}
$cols = mysql_num_fields($result);
echo '
'; echo mysql_field_name($result, $i); echo ' | ';
---|
'; echo $value; echo ' | ';
}
private function setCurPage($curPage){
if($curPage {
$curPage = 1;
}
else if($curPage > $this->totalPages)
{
$curPage = $this->totalPages;
}
$this->curPage = $curPage;
}
/*
显示分页页脚的信息
如首页,上一页,下一页,尾页等信息
*/
private function showFoot(){
echo '首页';
echo '上一页';
echo '下一页';
echo '尾页';
}
}
?>
方法二:
复制代码 代码如下:

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use
