In this way, we can know several pages.
For example, if the result of a list is 126 rows and 20 rows on one page are divided into 7 pages, right.
Our Code Manager is like this:
Total number of calculated rows: select count (*) from tablename where .....
Query the list select * from tablename where... Limit...
We can see that the first list is re-queried in this way without any optimization.
First, let's assume that the data update frequency is not very high. In this case, click 1st pages and 2nd pages... In fact, the first SQL statement on page n produces the same result. Is it a duplicate of the SQL statement. After we get the number of results on page 1, can we pass the results.
For example, if we link page 2nd to list. php? Page = 2 & count = 126
Add a judgment to the program:
if ($_get['count']) {$count = $_get['count'];} else {$count =select count(*) from tablename where …..}
After this optimization, if we only calculate the total number of pages on the first page, and the number of pages on the next page will not be used, then the efficiency will be improved.
In the case of fuzzy queries, we have an application. I estimate that most of the query results are smaller than 20, that is, there is only one page of results, therefore, it is unnecessary to calculate the total number and the efficiency of fuzzy search is relatively low. So I suddenly thought out of my original thinking. Why do we have to calculate the total number of rows and then retrieve the list?
In fact, you can query the list first. If the number of results in the list is 20, we can query the total number of rows. If the number is less than 20, there is only one page. The total number of rows is equal to the number of results in the list.
Pseudocode:
If ($ _ get ['page'] <2) {$ list = select * from tablename where... When the first page of limit is queried directly, the first 20 if (count ($ list) = 20) {$ count = select count (*) from tablename where .....} Else {$ count = count ($ list) ;}} else {$ count =$ _ get ['Count']; $ list = select * from tablename where... Limit page-1*20, page-1*20 + 20}