Home php教程 php手册 实现强大的翻页跳转功能(二)

实现强大的翻页跳转功能(二)

Jun 21, 2016 am 09:10 AM
echo gt lt page quot

翻页

前面介绍了简单的翻页功能实现,下面介绍的翻页功能更加强大,更加复杂,本站的非常论坛和非常文章就是使用这个循环翻页功能的.

循环翻页是前翻后翻加上数字共同实现的,具体的表现形式为:

页: prve > next

里面的数字表示各当前的页面,前翻 prve 和后翻 next 已不仅仅是当前页的前后翻转,而是更加复杂的数字控制前后翻转.

同以往一样,在进行程序设计之前,先理清一下思路,我建议读者在看完如何实现循环翻页的功能后,能自己动手实践一次,因为这里研究的一些方法和思路可能比较抽象.

首先我们大胆假设数据库里存有超过 1000 条的记录,我们希望当前显示 25 条记录,而数字翻转控制为 20,因此就有如下的显示结果:

页: 0 1 2 3 ......... 19 >> next

后翻后的显示结果:

页: prve > next

好,我们来看看其中的规律,一个固定的显示数字 25 ,一个固定的数字控制倍翻 20.我们可以利用这两个数字来实现循环翻页功能;

首先设置固定显示的变量:
$limit=20;
数据库初始变量的设置:
$start=0;
数据库记录总数为:$num;
页数变量:$page;

一个页数循环显示的程序如下:


...
$result=mysql_query("select * from table");
$num=mysql_numrows($result);
for ($page=0;$pageecho $page;
if ($page>0 && ($page%20)==0) {
break; //退出循环
}
}
?>

这段代码除了显示数字外,其它功能一概没有实现,因为多了数字控制翻转,所以必须要有几个变量来标记并识别这些控制量,这里用了 $s 来标记;这个变量是用来控制数字循环翻页控制的,现在可以看看实现循环翻页的完整代码 page.php:


$limit=25;
if (!empty($start)) $start=0;
if (!empty($s)) $s=0;

mysql_connect("localhost","","");
mysql_select_db(database);

//统计数据库记录总数
$result=mysql_query("select * from table");
$num=mysql_numrows($result);

$result=mysql_query("select * from table order by id limit $start,$limit");
$numb=mysql_numrows($result);
echo "

";
if (!empty($numb)) {
for($i=0;$i$val=mysql_result($result,$i,"val");
$val1=mysql_result($result,$i,"val1");
echo "";
}
}
echo "
$val $val1
";

//数字循环翻页的控制
echo "";
echo "";

//前翻控制
if ($s>20) {
if ($s==21) {
$st=$s-21;
} else {
$st=$s-20;
}
$pstart=$st*$limit;
echo "";
}
echo "";

//设置当前页对应页数无链接功能
$star=$start;

//注意循环的初始附值,仔细想想为什么不是 0
for ($page=$s;$page
$start=$page*$limit;
echo "";

//控制数字页面限制显示功能,控制只显示 20 页
if ($page>0 && ($page%20)==0) {
if ($s==0) {
$s=$s+21;
} else {
$s=$s+20;
}

$start=$start+$limit;

if ((($num/$limit)-1)>$page) {
echo "";
}
//注意跳出循环的控制
break;
}
}
echo "
页: echo "start=$pstart&s=$st>prve >>";

if($page!=$star/$limit) {
echo "echo "start=$start&s=$s>";
}

echo $page;

if($page!=$star/$limit) {
echo "";
}

echo "
echo "start=$start&s=$s>next
";
?>

以上的程已序可以完成强大的循环翻页功能.

还有一个翻页功能就是提交翻页,即在提交表单添入数据提交,然后程序跳转到该对应页,这个功能实现起来比较简单,就留给读者自己完成,这里不再介绍...



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

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ​​are springing up like mushrooms after a rain. One of the languages ​​that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

How to implement data paging and display optimization in Vue projects How to implement data paging and display optimization in Vue projects Oct 15, 2023 am 09:27 AM

Implementing data paging and display optimization in Vue projects. In Vue projects, when a page needs to display a large amount of data, data paging and display optimization usually need to be performed to improve user experience. This article will introduce how to use Vue to implement data paging and display optimization. , and provide specific code examples. 1. Data paging Data paging refers to dividing a large amount of data into multiple pages according to certain rules and displaying them on the page. You can use the following steps to implement data paging in a Vue project: Define the data source. First, define a

Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Laravel development: How to implement WebSockets communication using Laravel Echo and Pusher? Jun 13, 2023 pm 05:01 PM

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

Detailed explanation of the role and usage of the echo keyword in PHP Detailed explanation of the role and usage of the echo keyword in PHP Jun 28, 2023 pm 08:12 PM

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e

See all articles