


PHP implementation of paging: text paging and number paging_PHP tutorial
PHP implements paging: text paging and number paging
Source: http://www.ido321.com/1086.html
Recently, paging is used in projects. The paging function is a frequently used function, so it is encapsulated in the form of a function.
// 分页分装 /** * $pageType 分页类型 1是数字分页 2是文本分页 * 可以将$pageTotal,$page,$total等数据作为参数传递,或者在paging作为全局变量(推荐) */ function paging($pageType) { global $pageTotal,$page,$total; if($pageType == 1) { echo '<div id="pagenum">'; echo'<ul>'; for($i=0; $i < $pageTotal; $i++) { if($page == ($i+1)) { echo '<li>'.($i+1).'</li>'; } else { echo '<li>'.($i+1).'</li>'; } } echo'</ul>'; echo'</div>'; } else if($pageType == 2) { echo '<div id="pagetext">'; echo '<ul>'; echo '<li>'.$page.'/'.$pageTotal.'页 | </li>'; echo '<li>共有<strong>'.$total .'</strong>个会员 | </li>'; // 第一页 if($page == 1) { echo '<li>首页 | </li>'; echo '<li>上一页 | </li>'; } else { // $_SERVER["SCRIPT_NAME"]获取当前的脚本名字,方便移植 // 也可以自定义常量,常量值和脚本文件名一致 echo '<li>首页 | </li>'; echo '<li>上一页 | </li>'; } // 最后一页 if($page == $pageTotal) { echo '<li>下一页 | </li>'; echo '<li>尾页 | </li>'; } else { echo '<li>下一页 | </li>'; echo '<li>尾页 | </li>'; } echo '</ul>'; echo '</div>'; } }
Parameter explanation:
$pageTotal is the total number of pages, $page is the current page, $total is the total number of data obtained from the database;
For simplicity, all parameters are encapsulated
// 分页参数分装 /** * $sql 可以 获取数据总数的一个sql语句 * $size 每一页显示条数 */ function pageParam($sql,$size) { // 将所有涉及的参数设置全局变量 // $pagestart 某一页从哪里开始 // $total 总记录数 $page 某一页 $pageTotal 总页数 global $pagestart,$pagesize,$total,$page,$pageTotal; $pagesize = $size; // 获取数据总数 $total = mysql_num_rows(queryDB($sql)); // 错误处理,先判断是否存在 if(isset($_GET['page'])) { // 具体某一页 $page = $_GET['page']; // 判断是否为空(0是空)/小于0/是否是数字 if(empty($page) || $page < 0 || !is_numeric($page)) { $page = 1; } else { $page = intval($page); //取整,防止小数出现 } } else { // 初始化显示第1页 $page = 1; } // 数据库清零 if($total == 0) { // 设置为1 $pageTotal = 1; } else { // 分页的总页数(进一取整处理) $pageTotal = ceil($total / $pagesize); } // 页数大于总页码$total if($page > $pageTotal) { $page = $pageTotal; } // 当页从某一条记录开始 $pagestart = ($page - 1) * $pagesize; }
Parameter explanation:
$pagestart is when the page starts from a certain record, $pagesize is the number of records displayed on each page
In use, call pageParam first, then call paging
/** * 第一个 可以 获取数据总数的一个sql语句 * 第二个 每一页显示条数 */ pageParam("select userid from user",2);
<?php // 分页类型 1是数字分页 2是文本分页 paging(2); ?>
The calling position is selected according to the specific situation. The text is paginated as follows:
<?php // 分页类型 1是数字分页 2是文本分页 paging(1); ?>
Numbers are paginated as follows:


The style can be adjusted by yourself.
Next article: A small example of displaying a map using Google Maps API

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



Standby is a lock screen mode that activates when the iPhone is plugged into the charger and oriented in horizontal (or landscape) orientation. It consists of three different screens, one of which is displayed full screen time. Read on to learn how to change the style of your clock. StandBy's third screen displays times and dates in various themes that you can swipe vertically. Some themes also display additional information, such as temperature or next alarm. If you hold down any clock, you can switch between different themes, including Digital, Analog, World, Solar, and Floating. Float displays the time in large bubble numbers in customizable colors, Solar has a more standard font with a sun flare design in different colors, and World displays the world by highlighting

In iOS 17, Apple has overhauled its entire selection of ringtones and text tones, offering more than 20 new sounds that can be used for calls, text messages, alarms, and more. Here's how to see them. Many new ringtones are longer and sound more modern than older ringtones. They include arpeggio, broken, canopy, cabin, chirp, dawn, departure, dolop, journey, kettle, mercury, galaxy, quad, radial, scavenger, seedling, shelter, sprinkle, steps, story time , tease, tilt, unfold and valley. Reflection remains the default ringtone option. There are also 10+ new text tones available for incoming text messages, voicemails, incoming mail alerts, reminder alerts, and more. To access new ringtones and text tones, first, make sure your iPhone

This tutorial shows you how to find specific text or phrases on all open tabs in Chrome or Edge on Windows. Is there a way to do a text search on all open tabs in Chrome? Yes, you can use a free external web extension in Chrome to perform text searches on all open tabs without having to switch tabs manually. Some extensions like TabSearch and Ctrl-FPlus can help you achieve this easily. How to search text across all tabs in Google Chrome? Ctrl-FPlus is a free extension that makes it easy for users to search for a specific word, phrase or text across all tabs of their browser window. This expansion

The ability to generate random numbers or alphanumeric strings comes in handy in many situations. You can use it to spawn enemies or food at different locations in the game. You can also use it to suggest random passwords to users or create filenames to save files. I wrote a tutorial on how to generate random alphanumeric strings in PHP. I said at the beginning of this post that few events are truly random, and the same applies to random number or string generation. In this tutorial, I'll show you how to generate a pseudo-random alphanumeric string in JavaScript. Generating Random Numbers in JavaScript Let’s start by generating random numbers. The first method that comes to mind is Math.random(), which returns a float

Representing numbers as output is an interesting and important task when writing a program in any language. For integer types (data of type short, long, or medium), it is easy to represent numbers as output. For floating point numbers (float or double type), sometimes we need to round them to a specific number of decimal places. For example, if we want to represent 52.24568 as three decimal places, some preprocessing is required. In this article, we will introduce several techniques to represent floating point numbers to a specific number of decimal places by rounding. Among the different approaches, it is important to use a C-like format string, use the precision argument, and use the round() function from the math library. Let’s look at them one by one. with

Download the new Snipping Tool with text actions Although the new Snipping Tool is limited to development and canary versions, if you don’t want to wait, you can install the updated Windows 11 Snipping Tool (version number 11.2308.33.0) now. How this works: 1. Go ahead and open this website (visit) on your Windows PC. 2. Next, select "Product ID" and paste "9MZ95KL8MR0L" into the text field. 3. Switch to the "Quick" ring from the right drop-down menu and click Search. 4. Now, look for this version “2022.2308.33.0” in the search results that appear. 5. Right click on the one with MSIXBUNDLE extension and in context menu

We all know numbers that are not the square of any number, such as 2, 3, 5, 7, 8, etc. There are N non-square numbers, and it is impossible to know every number. So, in this article, we will explain everything about squareless or non-square numbers and ways to find the Nth non-square number in C++. Nth non-square number If a number is the square of an integer, then the number is called a perfect square. Some examples of perfect square numbers are -1issquareof14issquareof29issquareof316issquareof425issquareof5 If a number is not the square of any integer, then the number is called non-square. For example, the first 15 non-square numbers are -2,3,5,6,

Text documents are very important files in the system. They not only allow us to view a lot of text content, but also provide programming functions. However, after the win11 system was updated, many friends found that text documents could not be opened. At this time, we can open them directly by running them. Let’s take a look. Where to open a text document in win11 1. First press "win+r" on the keyboard to call up run. 2. Then enter "notepad" to create a new text document directly. 3. If we want to open an existing text document, we can also click on the file in the upper left corner and then click "Open".
