Under the PHP paging class is my own paging class, which can be modified as appropriate & nbsp; & lt ;? Php *** @ namePagersclass * @ authorRefer * @ copyrightwww.phpcq.com * @ versionAlpha1.0 * @ todo drop-down menu page --- From form Transfer & #20540;... PHP paging class
Below is my own paging class, which can be modified as appropriate
Get = (int) $ _ GET ['startrow']; $ this-> post = (int) $ _ POST ['pagenums']; $ this-> pageSize = $ pageSize; $ this-> pageTotal = ceil ($ total/$ pageSize); switch ($ _ GET ['method']) {default: $ this-> startRow = 1; $ this-> offset = 0; break; case 'first': $ this-> first (); break; case 'previous ': $ this-> previous (); break; case 'next': $ this-> next (); break; case 'last': $ this-> last (); break;}/*** homepage method **/public function first () {$ this-> startRow = 1; $ this-> offset = ($ this-> startRow-1) * $ this-> pageSize;}/*** previous page method **/public function previous () {$ this-> startRow = $ this-> get-1; if ($ this-> startRow <1) {$ this-> startRow = 1 ;} $ this-> offset = ($ this-> startRow-1) * $ this-> pageSize;}/*** next Page method **/public function next () {$ this-> startRow = $ this-> get + 1; if ($ this-> startRow> $ this-> pageTotal) {$ this-> startRow = $ this-> pageTotal;} $ this-> offset = ($ this-> startRow-1) * $ this-> pageSize ;} /*** last page method **/public function last () {$ this-> startRow = $ this-> pageTotal; $ this-> offset = ($ this-> startRow-1) * $ this-> pageSize ;} /*** flip the page from the drop-down menu ** @ return Int */public function numPages () {if ($ this-> post) {$ pageNums ="$ This-> post"; $ This-> startRow = $ this-> post; $ this-> offset = ($ this-> post-1) * $ this-> pageSize ;} for ($ I = 1; $ I <= $ this-> pageTotal; $ I ++) {if ($ I! = $ This-> post) {$ pageNums. ="$ I";}} Return $ pageNums;}/*** current page ** @ return Int */public function noncePage () {if ($ this-> post) {return $ this-> startRow = $ this-> post;} else {return $ this-> startRow = $ this-> startRow ;}}}
Call method:
$ Total = $ total-> total (); // total records $ pageSize = 15; // records displayed on each page $ pager = new Pager ($ total, $ pageSize ); if ($ pager-> post) {$ startRow = $ pager-> noncePage ();} $ startRow = $ pager-> startRow; $ pager-> numPages (); $ article-> query ("SELECT * FROM 'categories 'as c, 'articles' as n WHERE c. id = n. pid order by n. id desc limit $ pager-> offset, $ pageSize "); while ($ article-> fetchArray () {$ article-> data ['content'] = mb_subs Tr (strip_tags ($ article-> data ['content']), 0, 40, 'utf-8'); $ articleIndex [] = $ article-> data ;} $ article-> free ();} else {header ("location :? Act = login ") ;}$ view-> assign ('startrow', $ startRow); // caption $ view-> assign ('total ', $ total); // caption $ view-> assign ('pagenums', $ pager-> numPages ()); // pageNums $ view-> assign ('noncepage', $ pager-> noncePage ()); // pageNums $ view-> assign ('pagetotal', $ pager-> pageTotal); // pageTotal
Template page:
This article is from the "Qingyuan education" blog. For more information, see here. thank you! Log on to Qingyuan education official website to view more video tutorials.