Php paging example sharing. Copy the code as follows: page 1: url1 page 2: url2functionpages ($ url, $ totalnum, $ page, $ pagesize20) {$ urladd; $ url .; $ totalpageceil ($ t
The code is as follows:
// Page 1: url/1 page 2: url/2
Function pages ($ url, $ totalnum, $ page, $ pagesize = 20 ){
$ Urladd = '';
$ Url. = '/';
$ Totalpage = ceil ($ totalnum/$ pagesize );
If ($ totalpage <2) return '';
$ Page = min ($ totalpage, $ page );
$ Shownum = 5; // how many pages are displayed * 2
$ Start = max (1, $ page-$ shownum );
$ End = min ($ totalpage, $ page + $ shownum );
// Less than $ shownum to complete the left and right sides
$ Right = $ page + $ shownum-$ totalpage;
$ Right> 0 & $ start = max (1, $ start-= $ right );
$ Left = $ page-$ shownum;
$ Left <0 & $ end = min ($ totalpage, $ end-= $ left );
$ S = '';
$ Page! = 1 & $ s. ='◀';
If ($ start> 1) $ s. = '1'. ($ start> 2? '...':'').'';
For ($ I = $ start; $ I <= $ end; $ I ++ ){
If ($ I = $ page ){
$ S. = ''. $ I.''; // checked
} Else {
$ S. = ''. $ I .'';
}
}
If ($ end! = $ Totalpage) $ s. = ''. ($ totalpage-$ end> 1? '...': ''). $ Totalpage .'';
$ Page! = $ Totalpage & $ s. ='▶';
Return $ s;
}
Function mid ($ n, $ min, $ max ){
If ($ n <$ min) return $ min;
If ($ n> $ max) return $ max;
Return $ n;
}
Function page ($ page, $ n, $ pagesize ){
$ Total = ceil ($ n/$ pagesize );
$ Total <1 AND $ total = 1;
Return mid ($ page, 1, $ total );
}
For the backend part, we can do it in just a few words.
The code is as follows:
$ Pagesize = 20; // The number of users displayed on each page
$ N = user_count (); // total number of users
$ Page = page ($ page, $ n, $ pagesize); // The current page number.
$ Userlist = user_find ($ page, $ pagesize); // find the user on the current page
// Html part, paging effect, rendering directly to the page
$ Pagehtml = pages (url prefix, $ n, $ page, $ pagesize );
The http://www.bkjia.com/PHPjc/763012.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/763012.htmlTechArticle code is as follows: // paging function first page: url/1 second page: url/2 function pages ($ url, $ totalnum, $ page, $ pagesize = 20) {$ urladd = ''; $ url. = '/'; $ totalpage = ceil ($ t...