[Original] step-by-step paging of the paging intermediate tutorial I mentioned in the elementary tutorial that when there are many page numbers, this article mainly focuses on this topic. Welcome to shoot bricks. The source code is similar to the previous Elementary paging tutorial, but it is slightly improved in the output page turning link. what is step paging? Here, when the total number of pages reaches several hundred, if we follow the practices in the previous article, the page will become ugly and all the pages will be output, so it is unsightly, therefore, you need to control the number of output page numbers. If you are careful, see step-by-step paging of di [original] paging intermediate tutorial
In the preliminary tutorial, I mentioned that when there are many page numbers, this article mainly focuses on this. Welcome to shoot bricks.
The source code is similar to the previous Elementary paging tutorial, but it is slightly improved in the output page turning link.
What is step-by-step paging? Here is a brief introduction.
When the total number of pages reaches several hundred, if we follow the practice in the previous article, the page becomes ugly and all the pages are output, so it is unsightly, therefore, you need to control the number of output page numbers. If you are careful, check the discuz page. The final page number cannot exceed a certain number.
PHP code
Paging instance
$ Total_page? $ Total_page: $ page; // avoid $ _ GET ["page"] exceeding the total number of pages // The page turning link starts $ page_link = ""; if ($ total_page> 1) {$ page_link = "total {$ total_page} pages"; $ page_link. = "current page {$ page}"; $ page_link. = "homepage"; if ($ page> 1) {// when the page number is greater than 1, the page turning link of the previous page is displayed $ pre_page = $ page-1; $ page_link. = "<" ;}/// page flip list // Step-by-step page. the number of the page flip list is always 9 or custom. In this example, only 9 are displayed, four page numbers are displayed on the left and right of the current page. if ($ total_page> 9) {if ($ page> 4) {$ from = $ page-4; $ to = $ page + 4; if ($ to> $ total_page) {$ from = $ total_page-8; $ to = $ total_page;} else {$ from = 1; $ to = 9 ;}} else {$ from = 1; $ to = $ total_page;} for ($ I = $ from; $ I <= $ to; $ I ++) {if ($ I = $ page) {// highlight the current page number $ page_link. = "$ I";} else {$ page_link. = "$ I" ;}}// when the page number is smaller than the total page number, the next page flip link is displayed. $ next_page = $ page + 1; if ($ next_page <$ total_page) {$ page_link. = ">" ;}$ page_link. = "Last page";} // output record $ offset = ($ page-1) * $ page_size; $ query = mysql_query ("select * from product limit $ offset, $ page_size ") or die (mysql_error (); echo"
"; While ($ rs = mysql_fetch_array ($ query) {echo"
- {$ Rs ["id"]}-{$ rs ["ename"]}
";} Echo"
"; Echo"$ Page_link
";?>
------ Solution --------------------
A rare Green article ..
------ Solution --------------------
Good tutorial. suitable for beginners. I have my own paging class.