Discussion on php+mysql paging processing_PHP tutorial
Discussion on php+mysql paging processing The common paging processing process is: 1. Use select count(*) from tbl_name to obtain the total number of records to be paging 2. Calculate the total number of pages based on the number of records on each page: Total number of pages = ceil (Total number of records/number of records per page) 3. Calculate the starting position based on the current page number: starting position = (current page number-1)*number of records per page 4. Use select * from tbl_name limit starting position, Number of records per page Obtain the records to be displayed 5. List output related information In this process, the database needs to traverse the table twice to obtain the required data. Although limit will terminate the traversal after getting the specified number of records, the previous retrieval up to the "starting position" is wasted. A new algorithm is proposed here to discuss with everyone: 1. Use the user variables of mysql to split and extract the starting ID number of each page. 2. The number of records in the query result is the total number of pages. 3. Get the starting id of the current page based on the current page number. 4. Use select * from tbl_name where id>= starting id limit to get the records to be displayed. 5. List output related information can be seen in the latter query. Due to the use of id as the primary key, the database can directly locate the required record. This reduces query time. This query algorithm has a by-product: it can generate a duplicate record that connects the previous and next pages, that is, there is an overlapping record between each page. Of course, it's easy to get rid of him. The following is the test code: ="; } if($mode) $pagesize++; mysql_query("set @v:=-1"); // Define mysql user variable $rs = mysql_query("select @v:= (@v+1) as xh, id from data HAVING mod(xh,$pagesize)=0 order by id $order"); mysql_result_all($rs); // Check the distribution of each page echo $pages = mysql_num_rows($rs ); // Get the total number of pages if($mode) $pagesize--; // Test the paging results, $i represents the displayed page for($i=0;$i
[$i] $xh -- $id"; $rs1 = mysql_query("select * from data where id$expr$id order by id $order limit $pagesize"); mysql_result_all( $rs1); // Display related results} ?> mysql_result_all.inc I have posted this function many times, it is very useful for debugging programs function mysql_result_all($result,$format="") { echo ""; for($i=0;$i

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

1. First, we right-click the blank space of the taskbar and select the [Task Manager] option, or right-click the start logo, and then select the [Task Manager] option. 2. In the opened Task Manager interface, we click the [Services] tab on the far right. 3. In the opened [Service] tab, click the [Open Service] option below. 4. In the [Services] window that opens, right-click the [InternetConnectionSharing(ICS)] service, and then select the [Properties] option. 5. In the properties window that opens, change [Open with] to [Disabled], click [Apply] and then click [OK]. 6. Click the start logo, then click the shutdown button, select [Restart], and complete the computer restart.

With the popularity of mobile Internet, Toutiao has become one of the most popular news information platforms in my country. Many users hope to have multiple accounts on the Toutiao platform to meet different needs. So, how to open multiple Toutiao accounts? This article will introduce in detail the method and application process of opening multiple Toutiao accounts. 1. How to open multiple Toutiao accounts? The method of opening multiple Toutiao accounts is as follows: On the Toutiao platform, users can register accounts through different mobile phone numbers. Each mobile phone number can only register one Toutiao account, which means that users can use multiple mobile phone numbers to register multiple accounts. 2. Email registration: Use different email addresses to register a Toutiao account. Similar to mobile phone number registration, each email address can also register a Toutiao account. 3. Log in with third-party account

In the process of PHP development, dealing with special characters is a common problem, especially in string processing, special characters are often escaped. Among them, converting special characters into single quotes is a relatively common requirement, because in PHP, single quotes are a common way to wrap strings. In this article, we will explain how to handle special character conversion single quotes in PHP and provide specific code examples. In PHP, special characters include but are not limited to single quotes ('), double quotes ("), backslash (), etc. In strings

In today's fast-paced society, sleep quality problems are plaguing more and more people. In order to improve users' sleep quality, a group of special sleep anchors appeared on the Douyin platform. They interact with users through live broadcasts, share sleep tips, and provide relaxing music and sounds to help viewers fall asleep peacefully. So, are these sleep anchors profitable? This article will focus on this issue. 1. Are Douyin sleep anchors profitable? Douyin sleep anchors can indeed earn certain profits. First, they can receive gifts and transfers through the tipping function in the live broadcast room, and these benefits depend on their number of fans and audience satisfaction. Secondly, the Douyin platform will give the anchor a certain share based on the number of views, likes, shares and other data of the live broadcast. Some sleep anchors will also

There are two most common ways to paginate PHP arrays: using the array_slice() function: calculate the number of elements to skip, and then extract the specified range of elements. Use built-in iterators: implement the Iterator interface, and the rewind(), key(), current(), next(), and valid() methods are used to traverse elements within the specified range.

Processing strings in PHP is a very common operation, and removing the first character on the right is also a common need. In this article, I will show you how to remove the first character on the right using PHP code. First, let's look at a simple example of a string processing function that demonstrates how to remove the first character on the right:

Go language, as a powerful programming language, provides rich functions and libraries to process Chinese characters. Processing Chinese characters in the Go language requires correct handling of character encoding to avoid garbled characters and errors. The following will introduce how to process Chinese characters in the Go language and provide specific code examples. First, we need to understand some basic concepts. In computers, character encodings are the rules for mapping characters to numbers so that computers can recognize and process text data. Common character encodings include ASCII encoding, UTF-8

PHP Programming Tips: How to Handle the Last Semicolon In PHP programming, you often encounter situations where you need to handle the last semicolon. Especially in loops and conditional statements, it is easy to cause program errors by writing one less or one more semicolon. In order to avoid this situation, we can adopt some programming techniques to handle the last semicolon situation. The following are some common techniques and code examples for handling the last semicolon: 1. Use if statements to determine the last semicolon
