Two practical php paging codes-PHP source code

Source: Internet
Author: User
Paging refers to the number of equal pages for the total records that meet the conditions except the records displayed on each page. The principle is quite simple. The formula is $ totalceil ($ toalRecord $ perpageNum ); paging refers to the number of equal pages except the records displayed on each page based on the total records that meet the conditions. The principle is quite simple. The formula is $ total = ceil ($ toalRecord/$ perpageNum );

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;
}

Paging Code 2

// Pagination, {total number of records, number of records displayed per page, current page, maximum number of pages displayed, pagination url}

Function page ($ toalrecord, $ perpagenum, $ curpage, $ url ){
$ Total = ceil ($ toalrecord/$ perpagenum );
$ Pagearr = array_slice (range (1, $ total), max (0, $ curpage -~~ ($ Perpagenum/2), $ perpagenum );
If ($ pagearr [0]! = 1 ){
Array_unshift ($ pagearr, sprintf ("<", $ pagearr [0]-1 ));
}
If ($ pagearr [count ($ pagearr)-1]! = $ Total ){
Array_push ($ pagearr, sprintf (">", $ pagearr [count ($ pagearr)-1] + 1 ));
}
Foreach ($ pagearr as $ I =>&$ v ){
$ V = is_numeric ($ v )? "{$ V}": $ v;
}
Return "Homepage". implode ('', $ pagearr)." Last page ";
}

Call

Page (99/* Total records */, 9/* number of entries per page */, page/* Current page, starting from 1 */, 'HTTP: // www.111cn.net /? Page = '/* url prefix */);

Related Article

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.