php入门学习知识点二 PHP简单的分页过程与原理_php入门_脚本之家
php pagination
PHP简单的分页过程与原理分析,主要是读取数据库的时候,如果数据库内容较多,我们就需要分页显示。
require '../inc/conn.php';
?>
//初始参数设置
$pagesize=5 ; //分页大小
$pagenum=1 ; //默认为第一页
//第一步:获取当前是第几页
if($_GET){
if($_GET['pagenum']){
$pagenum=$_GET['pagenum'];
}
}
//第二步:获取当前分页的内容列表
$sql="Select * From message limit ".($pagenum-1)*$pagesize.",$pagesize ";
$result=mysql_query($sql);
while(($row=mysql_fetch_array($result))==true){
echo '
'.$row["title"].'';
}
//第三步:获取记录数
$sql="Select id From message";
$result=mysql_query($sql);
$rownum=mysql_num_rows($result);
//第四步:记算分页数
if(($rownum%$pagesize)==0){
$pagecount=$rownum/$pagesize;
}else{
$pagecount=(int)($rownum/$pagesize);
}
//第五步:得到分页链接
$url=$_SERVER["REQUEST_URI"];
$url=parse_url($url);
$url=$url["path"];
//第六步:输出分页链接
if($pagenum==1){
echo "[第一页] [上一页]";
}else{
echo "[第一页] [上一页]";
}
if($pagecount==$pagenum){
echo "[下一页] [最后一页]";
}else{
echo "[下一页] [最后一页]";
}
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks ago
By DDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks ago
By DDD
Where to find the Crane Control Keycard in Atomfall
3 weeks ago
By DDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months ago
By DDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks ago
By DDD

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
CakePHP Tutorial
1387
52

