Php Generic paging-php Tutorial

Source: Internet
Author: User
Php Generic paging class & lt ;? PhpinterfaceILink {publicfunctionparse ($ page, $ param );}? & Gt ;? & Lt ;? PhprequireILink. php; classLinkAdapterimplementsILink {*** @ paramunknown_type $ page * php Generic paging class
 

?

 GetAllPage ()} page, page {$ page-> getCurrentPage ()} "; $ links = $ this-> getLinkString ($ param ); if ($ page-> hasPrevious () $ temp. = "getCurrentPage ()-1 ). "'> Previous Page"; else {$ temp. = "previous page" ;}for ($ I = $ page-> getCurrentPage (); $ I <=$ page-> getAllPage () & $ I <= $ page-> getPerRecords (); $ I ++) {$ temp. = "{$ I}";} if ($ page-> hasNext () $ temp. = "getCurrentPage () + 1 ). "'> next page"; else {$ temp. = "next page";} return $ temp;} public function getLinkString ($ param) {$ str = ""; $ Attr = $ _ GET; unset ($ attr [$ param]); if ($ attr) {foreach ($ attr as $ key => $ val) {if ($ str = "") {$ str. = "? $ Key = $ val ";} else {$ str. = "& $ key = $ val" ;}}$ str. = "& $ param";} else {$ str. = "? $ Param ";}return $ str ;}}?>

??

 AllPage;}/*** @ return the $ allRecords */public function getAllRecords () {return $ this-> allRecords ;} /*** @ return the $ perRecords */public function getPerRecords () {return $ this-> perRecords ;} /*** @ return the $ currentPage */public function getCurrentPage () {return $ this-> currentPage ;} /*** @ param $ allPage the $ allPage to set */public function setAllPage ($ allPage) {$ this-> allPage = ($ allPage % $ this-> PerRecords = 0 )? ($ AllPage/$ this-> perRecords) :( $ allPage/$ this-> perRecords + 1); $ this-> allPage = intval ($ this-> allPage );} /*** @ param $ allRecords the $ allRecords to set */public function setAllRecords ($ allRecords) {$ this-> allRecords = $ allRecords ;} /*** @ param $ perRecords the $ perRecords to set */public function setPerRecords ($ perRecords) {$ this-> perRecords = $ perRecords ;} /*** @ param $ currentPage the $ currentPage to se T */public function setCurrentPage ($ currentPage) {if ($ currentPage <1) $ this-> currentPage = 1; else if ($ currentPage> $ this-> allPage) $ this-> currentPage = $ this-> allPage; else $ this-> currentPage = $ currentPage;} public function hasNext () {return $ this-> currentPage <$ this-> allPage;} public function hasPrevious () {return $ this-> currentPage> 1;} public function getEndIndex () {return ($ this-> currentPage-1) * $ th Is-> perRecords) + $ this-> perRecords)> $ this-> allRecords? ($ This-> currentPage-1) * $ this-> perRecords) + $ this-> perRecords)-$ this-> allRecords: $ this-> perRecords ;} public function getStartIndex () {return ($ this-> currentPage-1) * $ this-> perRecords ;}}?>

?

 List = $ list; $ this-> page = new Page ();} /***** @ param unknown_type $ Data volume displayed by rows * @ param unknown_type $ current page */public function init ($ rows = 5, $ current) {$ this-> page-> setAllRecords (count ($ this-> list); $ this-> page-> setPerRecords ($ rows ); $ this-> page-> setAllPage (count ($ this-> list); $ this-> page-> setCurrentPage ($ current ); $ this-> list = array_slice ($ this-> list, $ this-> page-> getStartIndex (), $ this-> page-> getEndIn Dex ();}/*** get the paging variable */public function getVar () {return $ this-> list ;} /*** @ return the $ param */public function getParam () {return $ this-> param ;} /*** @ param $ param the $ param to set */public function setParam ($ param) {$ this-> param = $ param ;} /*** load the plug-in information and obtain the generated link. the decorator mode * @ param unknown_type $ link */public function getLink ($ link = null) {if (! Empty ($ link) |! ($ Link instanceof ILink) $ link = new LinkAdapter (); return $ link-> parse ($ this-> page, $ this-> param) ;}}?>

?

 setParam("page");$page->init(30,$_REQUEST['page']);$list=$page->getVar();foreach($list as $val):echo $val.'
';endforeach;echo $page->getLink();?>

? Download

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.