Code generated by PAGE subscript of a web page (PHP backend method)

Source: Internet
Author: User

Code generated by PAGE subscript of a web page (PHP backend method)

Test legend:

:

Implementation Code:

/***** @ Param $ page (1 to infinity) * @ param $ num: The data goes up to one page * @ param $ total number of rows data rows * @ param $ length the maximum length of the cursor * @ return array */public function PageDate ($ page, $ num, $ rows, $ length) {// initialize data $ MaxPage = 0; // maximum page number $ MinPage = 0; // minimum page number $ ServerPage = 0; // page number displayed in the drop-down box $ PageData = array (); // All page number sets (selected in the user drop-down box) $ PageShowData = array (); // display the base page number set $ page = intval ($ page); if ($ rows = 0) {return $ data = array ('page' => $ page, 'maxpage' => $ MaxPage, 'minpage' => $ MinPage, 'serverpage' => $ ServerPage, 'pagedata' => $ PageData, 'pageshowdata' => $ PageShowData);} // get the maximum and minimum pages $ MaxPage = intval ($ rows/$ num); $ double = $ rows % $ num; if ($ double> 0.000000001) {$ MaxPage + = 1 ;}$ MinPage = 1; $ ServerPage = 1; // obtain all the items on the page for ($ I = 1; $ I <= $ MaxPage; $ I ++) {$ PageData [$ I] = $ I;} // correct the page correctness if ($ page <$ MinPage) {$ page = 1;} if ($ page> $ MaxPage) {$ page = 1 ;} /* generate the displayed page number label * // generate the code on the left side. if ($ page = $ MinPage) {$ PageShowData [1] = $ page ;} if ($ page> $ MinPage) {$ PageShowData [1] = $ MinPage; // $ PageShowData [2] = $ page-1; // <$ PageShowData [2] = '<'; // <if ($ page-2> $ MinPage) {$ PageShowData [3] = $ page-2; $ PageShowData [4] = $ page-1;} elseif ($ page-2 = $ MinPage) {$ PageShowData [3] = $ page-1;} // confirm the code for the selected page number. $ PageShowData [count ($ PageShowData) + 1] = $ page ;} $ COUNT = count ($ PageShowData) + 1; // generate the code block on the right if ($ page = $ MaxPage) {return $ data = array ('page' => $ page, 'maxpage' => $ MaxPage, 'minpage' => $ MinPage, 'serverpage' => $ ServerPage, 'pagedata' => $ PageData, 'pageshowdata' => $ PageShowData);} if ($ page <$ MaxPage) {if ($ MaxPage-$ page> = 2) {$ j = 1; for ($ I = $ COUNT; $ I <= $ length; $ I ++) {$ PageShowData [$ I] = $ page + $ j; $ j ++; if ($ PageShowData [$ I] ==$ MaxPage-1) {break ;}}$ COUNT = count ($ PageShowData) + 1; // $ PageShowData [$ COUNT] = $ page + 1; // >>$ PageShowData [$ COUNT] = '> '; $ PageShowData [$ COUNT + 1] = $ MaxPage; // obtain the selected parameter $ ServerPage = $ PageShowData [$ COUNT-1] + 1; if ($ ServerPage> $ MaxPage) {$ ServerPage = 1;} return $ data = array ('page' => $ page, 'maxpage' => $ MaxPage, 'minpage' => $ MinPage, 'serverpage' => $ ServerPage, 'pagedata' => $ PageData, 'pageshowdata' => $ PageShowData );}}

This article is from the IT985 blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.