Code of the pagination function program for Php

Source: Internet
Author: User
The code is as follows: Copy code
/*
* Front page
 *
* $ Page_array = array (
* 'Totle' => 10, // total number
* 'Dispage' => 10, // Number of Entries displayed on each page
* 'URL' => '/article/list/', // url address
* 'Now _ page', => 1, // Current page number
*);
 *
* @ Return pagenav
*/
Function front_page ($ page_array ){
 
// Paging judgment
$ Lastpage = ceil ($ page_array ['total']/$ page_array ['dispage']); // The last page.
$ Page_array ['Now _ page'] = min ($ lastpage, $ page_array ['Now _ page']); // compare the current page number and the last page
$ Prepage = $ page_array ['Now _ page']-1; // Previous page
$ Nextpage = ($ page_array ['Now _ page'] = $ lastpage? 0: $ page_array ['Now _ page'] + 1); // Next page
$ Firstcount = ($ page_array ['Now _ page']-1) * $ page_array ['dispage'];
If ($ lastpage <= 1) return false; // if the last page is smaller than 1, the system returns
 
// Homepage
If ($ prepage ){
$ Page_array [] = "<a href = '{$ page_array ['URL']}". "1/'> homepage </a> ";
} Else {
$ Page_array [] = "<span class = \" nolink \ "> homepage </span> ";
    }
// Previous Page
If ($ prepage ){
$ Page_array [] = "<a href = '{$ page_array ['URL']} $ prepage/'> Previous Page </a> ";
} Else {
$ Page_array [] = '';
    }
 
// Number of displayed numbers
$ Pagenum = 5;
$ Offset = 2; // Two offsets
$ From = $ page_array ['Now _ page']-$ offset; // start
$ To = $ page_array ['Now _ page'] + $ pagenum-$ offset-1; // terminate
If ($ pagenum> $ lastpage ){
$ From = 1;
$ To = $ lastpage;
} Else {
If ($ from <1 ){
$ To = $ page_array ['Now _ page'] + 1-$ from;
$ From = 1;
If ($ to-$ from) <$ pagenum & ($ to-$ from) <$ lastpage ){
$ To = $ pagenum;
            }
} Elseif ($ to> $ lastpage ){
$ From = $ page_array ['Now _ page']-$ lastpage + $;
$ To = $ lastpage;
If ($ to-$ from) <$ pagenum & ($ to-$ from) <$ lastpage ){
$ From = $ lastpage-$ pagenum + 1;
            }
        }
    }
For ($ I = $ from; $ I <= $ to; $ I ++ ){
If ($ I = $ page_array ['Now _ page']) {
$ Pagenav. = "<a href = \" # \ "title = \" \ "> $ I </a> ";
} Else {
$ Pagenav. = "<a href = \" {$ page_array ['URL']} $ I/\ "title = \" \ "> $ I </a> ";
 
        }
    }
// Numeric paging
$ Page_array [] = $ pagenav;
// Next page
If ($ nextpage ){
$ Page_array [] = "<a href = '{$ page_array ['URL']}". "$ nextpage/'> Next page </a> ";
} Else {
$ Page_array [] = '';
    }
// Last Page
If ($ nextpage ){
$ Page_array [] = "<a href = '{$ page_array ['URL']}". "$ lastpage/'> last page </a> ";
} Else {
$ Page_array [] = '<span class = "nolink"> Last page </span> ';
    }
// Number of records
$ Page_array [] = "<span> per page ". $ page_array ['dispage']. "Items </span> <span> Total ". $ page_array ['total']. "Records </span> ";
// Number of minutes
$ Page_array [] = "total". $ lastpage. "page ";
 
// Jump
$ Page_array [] = '<span> Jump to: </span> <input size = "4" id = "pagenu" type = "text" onkeydown = "javascript: if (event. keyCode = 13) {var page = (this. value <0 )? 1: this. value; location = \ ''. $ page_array ['URL']. '\' + page;}"/>
<A href = "javascript: void (0)" onclick = "javascript: var spage(({w.doc ument. getElementById (\ 'pagenu \ '). value == \'\')? 1: too many doc ument. getElementById (\ 'pagenu \'). value; location = \''. $ page_array ['URL']. '\' + spage; "> Go </a> ';
// Total number of the first page
$ Firstcount = $ firstcount <1? 0: $ firstcount;
Return array ('pagenav' => $ page_array, 'limit' => $ firstcount, 'offset' => $ page_array ['dispage'], 'allpage' => $ lastpage );
}

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.