PHP+Mysql development of paging and understanding of paging principles
What is paging technology
Paging is a technology that displays all data to the user in segments. The user does not see all the data every time , but a part of it. If you do not find the content you want for self-study, the user can convert the visible content by setting page numbers or turning pages until you find the content you want. In fact, this is very similar to reading books. Similar.
The meaning of paging
Paging is indeed effective, but it will definitely increase the complexity of the system, but can it not be paginated? Of course it is possible if the amount of data is small. But for enterprise information systems, the amount of data will not be limited to a small range. If you desperately Select * from a certain table and then throw the returned data to the customer, Even if customers can tolerate thousands of dazzling tabular data, busy networks and stressed servers will raise their silent protests, and sometimes even end with an outright strike. This ending is a bit like an ancient tyrant who did whatever he wanted. The story between him and his intolerable subjects.
The programmer is not a tyrant. He hopes that the program will make life better instead of worse. Considering the fact that enterprise information systems are mostly three-layer or even more-layer architecture, the program Employees should use paging when displaying data to customers. If he does not want to be overwhelmed by complaints or woken up by a phone call in the middle of the night.
How to implement paging
The so-called paging display means that the result set in the database is displayed one by one. Here we need to use the limit command in the Mysql statement.
How to segment, which segment is currently in (How many records per page, what is the current page)
The first 10 records:
select * from table limit 0,10
The 11th to 20th records:
select * from table limit 10,10
The 21st to 30th records Record:
select * from table limit 20,10
You can see the pattern from the above
(Current page number - 1) PHP file
conn.php Connection database filemupage.php Pagination complete file
Required mysql database
First of all, let’s sort out the development ideas and processes of the paging function
Connect to the database- Transmit from the database to us Desired data
- Use sql statement to write to obtain paging data
- Pass the sql statement into our database
- Process the data we get and display it on the page
- Get the total number of data, calculate the number of pages and the displayed data and offset.
- Initialize the paging data and omit processing of the header and tail parts
- Set the paging bar style display