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 > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how PHP+MYSQL paging is operated, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
It's a simple thing to write php, but it can be difficult for a little brother.
Because there are so many books in my hands. I can't read it. I can't say it clearly. °
This skill is easy for an expert, but it can be difficult for a beginner.
If you are also a beginner, I believe this article can give you a little bit of income.
Start
If you want to have the effect of dividing, you have to think about it first, don't you?
What data do you need if you want to share?
1 you have to decide how much data ($pagesize) you need to divide it in order to get the variable °.
What is the total amount of data? ($total) if not, it is equivalent to not being divisor.
3 when we want to go to school, we have to tell the program that we have to go to ($p) °.
Mysql
With the above three, except that 13 is self-determined, part of 2 must be calculated from the data store.
The key point is the method of sql. The method of sql has a limit.
Its usage is
Starting position of limit, number of materials taken
Therefore, we directly use its starting position to get our data, and the number of data obtained is the degree of each cycle we own.
Examples
Assuming that the amount of data is 8 tons of data, and we want one pack every 3 tons, the sql method is as follows:
The first one = = > take out the 0pi, the first and the second
Select * from data sheet limit 0pr 3
Take out 3, 4, 4, 5, 3.
Select * from data sheet limit 3pm 3
But because of the lack of data, we can actually only take out 6, 7, 2, 4, 6, 7, 7, 8, 3, 4, 7, 8, 3, 8, 3, 3, 3, 4, 7, 7, 8, 3, 2, 4, 4, 4, 4, 4, 4, 6, 7, 7, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
Select * from data sheet limit 6
Inspection and calculation
With the above example, we should first count the total number of data and then calculate the number of variables.
Total number
This section is known from the database, so you can use the following ways
$result = mysql_query ("select * from data sheet"); / / method of fetching all data
$total=mysql_num_rows ($result); / / Total number of data obtained
8 / 3. 2.
We can use a php function ceil here.
Its function can be used to calculate the minimum integer larger than the number of variables (floating numbers, those with small digits).
So the total number is $totalpages= ceil ($total/ $pagesize)
The beginning of division
Before dividing up, we have to decide on the number of variables in the first chapter, which is set to $p.
In addition, the number of friends has been counted since 0, that is,
P=0--> 1, which is taken from 0. The algorithm-- & gt $p*$pagesize-->0*3=0
The second version of $p=1-->, which is taken from the third. The algorithm-& gt $p*$pagesize-->1*3=3
The third version of $p=2-->, starting from the 6th, the algorithm-& gt $p*$pagesize-->2*3=6
It's OK if you want to start from 1, but you need to use it again.
$p=1--> 1, which is taken from 0. The algorithm-- & gt ($pmae1) * $pagesize-->0*3=0
The second version of $p=2-->, which is taken from the third, and the algorithm-- & gt ($pmur1) * $pagesize-->1*3=3
The third version of $p=3-->, which is taken from the 6th, and the algorithm-& gt ($pmur1) * $pagesize-->2*3=6
Next, let's take a look at the method.
The first prize = > $pendant 0, take out 0Phone1Jet 2 triplets
Select * from data sheet limit 0pr 3
Select * from data sheet limit $p * $pagesize, $pagesize
The second prize = > $pendant 1, take out the third quarter, the fourth quarter and the fifth quarter.
Select * from data sheet limit $p* $pagesize, $pagesize
The third prize = > $pendant 2, take out 6, 7, 7, 8, 3.
Select * from data sheet limit 6
Select * from data sheet limit $p* $pagesize, $pagesize
In accordance with the above, the division method obtained is
Select * from data sheet limit $p* $pagesize, $pagesize
Skip to the specified floor
In addition, how do we divide the number of $p programs?
Generally speaking, the value of $p is passed into the
The first time
The second chapter
The third chapter
.
.
Of course, you can also use other ways to do.. However, it is not mentioned here.
[@ more@]
Carry out a training program
Then show a complete code flow to let you know the whole process:
> chapter 1
The above is how the paging of PHP+MYSQL works. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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.