实用的简单PHP分页集合包括使用方法
收集了三个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

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



The hard disk serial number is an important identifier of the hard disk and is usually used to uniquely identify the hard disk and identify the hardware. In some cases, we may need to query the hard drive serial number, such as when installing an operating system, finding the correct device driver, or performing hard drive repairs. This article will introduce some simple methods to help you check the hard drive serial number. Method 1: Use Windows Command Prompt to open the command prompt. In Windows system, press Win+R keys, enter "cmd" and press Enter key to open the command

The DirectX repair tool is a professional system tool. Its main function is to detect the DirectX status of the current system. If an abnormality is found, it can be repaired directly. There may be many users who don’t know how to use the DirectX repair tool. Let’s take a look at the detailed tutorial below. 1. Use repair tool software to perform repair detection. 2. If it prompts that there is an abnormal problem in the C++ component after the repair is completed, please click the Cancel button, and then click the Tools menu bar. 3. Click the Options button, select the extension, and click the Start Extension button. 4. After the expansion is completed, re-detect and repair it. 5. If the problem is still not solved after the repair tool operation is completed, you can try to uninstall and reinstall the program that reported the error.

Many friends still don’t know how to use Baidu Netdisk, so the editor will explain how to use Baidu Netdisk below. If you are in need, hurry up and take a look. I believe it will be helpful to everyone. Step 1: Log in directly after installing Baidu Netdisk (as shown in the picture); Step 2: Then select "My Sharing" and "Transfer List" according to the page prompts (as shown in the picture); Step 3: In "Friend Sharing", you can share pictures and files directly with friends (as shown in the picture); Step 4: Then select "Share" and then select computer files or network disk files (as shown in the picture); Fifth Step 1: Then you can find friends (as shown in the picture); Step 6: You can also find the functions you need in the "Function Treasure Box" (as shown in the picture). The above is the editor’s opinion

It is difficult to implement collection-like functions in the Go language, which is a problem that troubles many developers. Compared with other programming languages such as Python or Java, the Go language does not have built-in collection types, such as set, map, etc., which brings some challenges to developers when implementing collection functions. First, let's take a look at why it is difficult to implement collection-like functionality directly in the Go language. In the Go language, the most commonly used data structures are slice and map. They can complete collection-like functions, but

Potplayer is a very powerful media player, but many friends still don’t know how to use potplayer. Today I will introduce how to use potplayer in detail, hoping to help everyone. 1. PotPlayer shortcut keys. The default common shortcut keys for PotPlayer player are as follows: (1) Play/pause: space (2) Volume: mouse wheel, up and down arrow keys (3) forward/backward: left and right arrow keys (4) bookmark: P- Add bookmarks, H-view bookmarks (5) full screen/restore: Enter (6) multiple speeds: C-accelerate, 7) Previous/next frame: D/

The KMS Activation Tool is a software tool used to activate Microsoft Windows and Office products. KMS is the abbreviation of KeyManagementService, which is key management service. The KMS activation tool simulates the functions of the KMS server so that the computer can connect to the virtual KMS server to activate Windows and Office products. The KMS activation tool is small in size and powerful in function. It can be permanently activated with one click. It can activate any version of the window system and any version of Office software without being connected to the Internet. It is currently the most successful and frequently updated Windows activation tool. Today I will introduce it Let me introduce to you the kms activation work

How to use the shortcut keys for merging cells In daily work, we often need to edit and format tables. Merging cells is a common operation that can merge multiple adjacent cells into one cell to improve the beauty of the table and the information display effect. In mainstream spreadsheet software such as Microsoft Excel and Google Sheets, the operation of merging cells is very simple and can be achieved through shortcut keys. The following will introduce the shortcut key usage for merging cells in these two software. exist

PyCharm is a professional Python integrated development environment (IDE) developed by JetBrains. It provides Python developers with powerful functions and tools, making writing Python code more efficient and convenient. PyCharm supports multiple operating systems, including Windows, macOS and Linux, and also supports multiple Python versions, and provides a wealth of plug-ins and extension functions to facilitate developers to customize the IDE environment according to their own needs. P
