In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to achieve PHP pagination, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Only the design ideas, specific security issues, and whether to update synchronously can be added and modified according to specific requirements:
The PHP paging technology commonly used by people in the past usually needs to count the total number of pieces of information in the database before it can be judged and paged, that is to say, each paging has to make two calls to the database, which is very inefficient in the face of large amounts of data and high concurrent queries. I used to worry about this problem all the time, but I didn't think of a suitable solution. I suddenly met a miracle in my sleep today. The specific analysis principle is as follows: (the red part is the difference after optimization, the train of thought uses the most primitive code writing, in order to take care of the newcomer)
Original paging technology: including technologies also used by many open source programs
Generally speaking, the database information is counted, and then the paging class is called, and each time it has to go through two database query operations.
Example (original paging technology): two database queries are performed each time.
The copy code is as follows:
$sqlstr= "select count (*) as total from tablename"
$sql=mysql_query ($sql) or die ("error")
$info=mysql_fetch_array ($sql); / / first database call
$total=$info ["total"]; / / the database query operation of the total number of information items is performed each time the page is turned.
$pagesize=10; / / display quantity per page
$page=$_GET ["page"]? max (intval ($_ GET ["page"]), 1): 1
If ($total) {
$sql= "select * from tablename limit" ($page-1) * $pagesize ", $pagesize"
$sql=mysql_query ($sql) or die ("error"); / / second database query operation
$info=mysql_fetch_array ($sql)
Do {
.
} while ($info=mysql_fetch_array ($sql))
Include ("page_class.php"); / / call the paging class
$url= "url.php?page=" / / assume that the current page is URL.PHP
Echo $get_page=new get_page ($url,$total,$pagesize,$page); / / URL is the URL address to be paged
}
/ / optimized paging technology (only need to count the information on the first call)
If (isset ($_ GET ["total"]) {/ / you only need to count the total number of messages once.
$total=intval ($_ GET ["total"])
/ / the total amount of information in the future can be transmitted through GET, which saves the database load of 1max 2.
} else {
$sqlstr= "select count (*) as total from tablename"
$sql=mysql_query ($sql) or die ("error")
$info=mysql_fetch_array ($sql); / / first database call
$total=$info ["total"]
} / / Total number of messages
$pagesize=10; / / display quantity per page
$page=$_GET ["page"]? max (intval ($_ GET ["page"]), 1): 1
If ($total) {
$sql= "select * from tablename limit" ($page-1) * $pagesize ", $pagesize"
$sql=mysql_query ($sql) or die ("error"); / / second database query operation
$info=mysql_fetch_array ($sql)
Do {
.
} while ($info=mysql_fetch_array ($sql))
Include ("page_class.php"); / / call the paging class
$url= "url.php?total=$total&page=" / / assume that the current page is URL.PHP
Echo $get_page=new get_page ($url,$total,$pagesize,$page); / / URL is the URL address to be paged
}
The above is all the contents of the article "how to Page PHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.