Several different styles of php paging code (1/8)-PHP source code

Source: Internet
Author: User
Ec (2); functionoutPege ($ ps tutorial, $ page) {$ ps Total Information $ page Current page quantity $ max list max $ min list min $ max & nbsp; & nbsp; ($ page & gt; 5 )? $ Page + 5:10; if ($ max & gt; $ ps) $ max $ ps; $ min & nbsp; & script ec (2); script

Function outPege ($ PS tutorial, $ page)
{
// $ Ps cumulative information $ current page number of page $ max maximum number of list $ min minimum value of list
$ Max = ($ page> = 5 )? $ Page + 5: 10;
If ($ max> $ ps) $ max = $ ps;
$ Min = ($ page-5 );
If ($ min <1) $ min = 1;
If ($ page> 1) $ pagelist = "Homepage ";
For ($ I = $ min; $ I <= $ max; $ I ++ ){
$ Pagelist. = ($ I! = $ Page )? "{$ I}": "{$ page }";
}
$ Pagelist. = ($ page >=$ ps )? '':" Last page ";
Return $ pagelist;
}

// Method 2

/**
* Display paging Function
* Total number of records, current page number of currentpage, number of records on each page of rows, and length of the listpage page number list.
*/
Function showpage ($ records, $ currentpage, $ rows = 20, $ listpages = 7 ){
If ($ records <1) return '';
If ($ rows <1) $ rows = 20;
If ($ listpages <3) $ listpages = 7;
$ Action = $ _ SERVER ['query _ string']; // get the address bar? Post content
If ($ action) {// remove the content of page =...
$ Action = preg_replace ("/& page [^ &] */", "", $ action );
$ Action = preg_replace ("/page [^ &] * & */", "", $ action );
}
If ($ action) $ action. = '&';
$ Maxpage = ceil ($ records/$ rows); // obtain the maximum number of pages by performing an integer operation.
$ Middlepage = floor ($ listpages/2); // trim to get half of the page number to be displayed.
If ($ currentpage <1 | $ currentpage> $ maxpage) $ currentpage = 1;
$ Startpage = $ currentpage-$ middlepage;
If ($ maxpage-$ currentpage <= $ middlepage) $ startpage = $ maxpage-$ listpages;
If ($ startpage <2) $ startpage = 2; // The start page is calculated successfully.
$ Endpage = $ startpage + $ listpages;
If ($ endpage> $ maxpage) $ endpage = $ maxpage; // the calculation of the end page is complete.
If ($ currentpage! = 1 ){
$ Pagestr = "1 ";
} Else {
$ Pagestr = "1 ";
}

Homepage 1 2 3 4 5 6 7 8 last page

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.