Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of the principle of php pagination

2024-05-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail the example analysis on the principle of php paging. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Paging display is a very common way to browse and display large amounts of data, and it is one of the most common events handled in web programming. For veterans of web programming, writing this kind of code is as natural as breathing, but for beginners, it is often confusing, so this article is specially written to explain the problem in detail.

First, the principle of paging:

The so-called paging display is to artificially divide the result set in the database into segments to display, here you need two initial parameters:

How many records per page ($PageSize)?

What is the current page ($CurrentPageID)?

Now just give me another result set and I can display a specific result.

As for other parameters, such as the previous page ($PReviousPageID), the next page ($NextPageID), the total number of pages ($numPages), etc., can be obtained from the previous few things.

Take the MySQL database as an example. If you want to intercept a section of content from the table, the sql statement can be used: select * from table limit offset, rows. Take a look at the following set of sql statements and try to find the rules in it.

The first 10 records: select * from table limit 0pm 10

Records 11 to 20: select * from table limit 10

Records 21 to 30: select * from table limit 20jin10

……

This set of sql statements is actually a sql statement that fetches each page of data in the table when $PageSize=10. We can sum up a template like this:

Select * from table limit ($CurrentPageID-1) * $PageSize, $PageSize

Compare this template with the corresponding value with the above set of sql statements to see if that's the case. Once you've solved the most important question of how to get the data, all that's left is to pass the parameters, construct the appropriate sql statement, and then use php to get the data from the database and display it.

2. Paging code description: five steps

There is a full explanation in the code, which can be copied into your notepad and used directly.

Employee information list

Paging implementation code:

This is the end of this article on "sample Analysis of the principle of php pagination". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report