Php paging class code example, which can be used in the php Framework
- // Php paging code
- Class page {
- Public $ page; // current page
- Public $ pagenum; // Number of pages
- Public $ pagesize; // number of entries per page
- Public function _ construct ($ count, $ pagesize ){
- $ This-> pagenum = ceil ($ count/$ pagesize );
- $ This-> pagesize = $ pagesize;
- $ This-> page = (isset ($ _ GET ['P']) & $ _ GET ['P']> 0 )? Intval ($ _ GET ['P']): 1;
- }
- /**
- * Get the get parameter passed after the url
- */
- Public function getUrl (){
- $ Url = 'index. php? '. Http_build_query ($ _ GET );
- $ Url = preg_replace ('/[?, &] P = (\ w) +/', '', $ url );
- $ Url. = (strpos ($ url ,"? ") = False )? '? ':'&';
- Return $ url;
- }
- /**
- * Retrieve html pages
- */
- Public function getPage (){
- $ Url = $ this-> getUrl ();
- $ Start = $ this-> page-5;
- $ Start = $ start> 0? $ Start: 1;
- $ End = $ start + 9;
- $ End = $ end <$ this-> pagenum? $ End: $ this-> pagenum;
- $ Pagestr = '';
- If ($ this-> page> 5 ){
- $ Pagestr = "homepage ";
- }
- If ($ this-> page! = 1 ){
- $ Pagestr. = "page-1)."> Previous page ";
- }
- For ($ I = $ start; $ I <= $ end; $ I ++ ){
- $ Pagestr. = "". $ I ."";
- }
- If ($ this-> page! = $ This-> pagenum ){
- $ Pagestr. = "page + 1)."> Next page ";
- }
- If ($ this-> page + 5 <$ this-> pagenum ){
- $ Pagestr. = "pagenum."> last page ";
- }
- Return $ pagestr;
- } // Edit: bbs.it-home.org
- }
- // Paging code test
- $ Page = new page (100,10 );
- $ Str = $ page-> getPage ();
- Echo $ str;
- ?>
|