Two omnipotent php paging classes

Source: Internet
Author: User
This article mainly introduces the omnipotent php paging class, which is especially useful. Do not miss it if you need to use the php paging class.

This article mainly introduces the omnipotent php paging class, which is especially useful. Do not miss it if you need to use the php paging class.

<? Makewebs/php/2013080344935.html "> php/** To change this template, choose Tools | Templates * and open the template in the editor. * // ** paging class * usage: * $ page = new Page (); * $ page-> init (1000, 20 ); * $ page-> setNotActiveTemplate ('{a}'); * $ page-> setActiveTemplate ('{a}'); * echo $ page-> show (); * ** @ author wind place */class Page {/*** total number of items */private $ total;/*** size per Page */private $ pageSize; /***** total page number */private $ pageNum;/***** current page */private $ page;/***** address */private $ uri; /*** paging variable */private $ pageParam;/*** limit xx, XX */private $ limit; /*** display the number by page */private $ listnum = 8; /***** pagination display template * Available Variable Parameter * {total} total number of data entries * {pagesize} number of entries per page * {start} number of entries starting on this page * {end} number of entries ending on this page * {pagenum} total number of pages * {frist} homepage * {pre} previous page * {next} next page * {last} last page * {list} number page * {goto} jump button */private $ template ='

Total {total} pieces of data each page displays {pagesize} pieces of data. total {start}-{end} pieces of data on this page include {pagenum} pages.

    {Frist} {pre} {list} {next} {last} {goto}

';/*** Selected paging link template */private $ activeTemplate ='
  • {Text}
  • ';/*** Unselected paging link template */private $ notActiveTemplate ='
  • {Text}
  • ';/*** Display text setting */private $ config = array ('frist' => 'homepage', 'pre' => 'pre ', 'Next' => 'Next page', 'last' => 'last page '); /*** initialize * @ param type $ total number of items * @ param type $ pageSize size per page * @ param type $ param url additional parameter * @ param type $ pageParam paging variable * /public function init ($ total, $ pageSize, $ param = '', $ pageParam = 'page') {$ this-> total = intval ($ total ); $ this-> pageSize = intval ($ pageSize); $ this-> pageParam = $ pageParam; $ t His-> uri = $ this-> geturi ($ param); $ this-> pageNum = ceil ($ this-> total/$ this-> pageSize ); $ this-> page = $ this-> setPage (); $ this-> limit = $ this-> setlimit ();} /*** set the paging template * @ param type $ template configuration */public function setTemplate ($ template) {$ this-> template = $ template ;} /*** set the selected Page Template * @ param type $ activeTemplate template configuration */public function setActiveTemplate ($ activeTemplate) {$ this-> activeTemplate = $ activeTe Mplate;}/*** set the unselected Page Template * @ param type $ notActiveTemplate template configuration */public function setNotActiveTemplate ($ notActiveTemplate) {$ this-> notActiveTemplate = $ notActiveTemplate ;} /*** return pagination * @ return type */public function show () {return str_ireplace (array ('{total}', '{pagesize }', '{start}', '{end}', '{pagenum}', '{frist}', '{pre}', '{next }', '{last}', '{list}', '{goto}',), array ($ this-> total, $ this-> setPageSize (), $ this -> Star (), $ this-> end (), $ this-> pageNum, $ this-> frist (), $ this-> prev (), $ this-> next (), $ this-> last (), $ this-> pagelist (), $ this-> gopage (),), $ this-> template);}/*** get the start Number of limit * @ return type */public function getOffset () {return ($ this-> page-1) * $ this-> pageSize;}/*** set LIMIT * @ return type */private function setlimit () {return "limit ". ($ this-> page-1) * $ this-> pageSize. ", {$ this-> pageSize}";}/*** get Limit * @ param type $ args * @ return type */public function _ get ($ args) {if ($ args = "limit ") {return $ this-> limit;} else {return null;}/*** initialize the current page * @ return int */private function setPage () {if (! Empty ($ _ GET [$ this-> pageParam]) {if ($ _ GET [$ this-> pageParam]> 0) {if ($ _ GET [$ this-> pageParam]> $ this-> pageNum) return $ this-> pageNum; elsereturn $ _ GET [$ this-> pageParam] ;}} return 1 ;} /*** initialize url * @ param type $ param * @ return string */private function geturi ($ param) {$ url = $ _ SERVER ['request _ url']. (strpos ($ _ SERVER ['request _ URI '], "? ")? "":"? "). $ Param; $ parse = parse_url ($ url); if (isset ($ parse ["query"]) {parse_str ($ parse ["query"], $ params ); unset ($ params ["page"]); $ url = $ parse ["path"]. "? ". Http_build_query ($ params); return $ url;} else {return $ url;}/*** number of entries starting on this page * @ return int */private function star () {if ($ this-> total = 0) {return 0;} else {return ($ this-> page-1) * $ this-> pageSize + 1 ;}} /*** Number of end entries on the current page * @ return type */private function end () {return min ($ this-> page * $ this-> pageSize, $ this-> total);}/*** set the current page size * @ return type */private function setPageSize () {return $ this-> end () -$ this-> star () + 1;}/*** homepage * @ return type */private function frist () {$ html = ''; if ($ this-> page = 1) {$ html. = $ this-> replace ("{$ this-> uri} & page = 1", $ this-> config ['frist '], true );} else {$ html. = $ this-> replace ("{$ this-> uri} & page = 1", $ this-> config ['frist '], false );} return $ html;}/*** previous page * @ return type */private function prev () {$ html = ''; if ($ this-> page> 1) {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> page-1), $ this-> config ['pre'], false);} else {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> page-1), $ this-> config ['pre'], true);} return $ html ;} /*** paging number list * @ return type */private function pagelist () {$ linkpage = ""; $ lastlist = floor ($ this-> listnum/2 ); for ($ I = $ lastlist; $ I >=1; $ I --) {$ page = $ this-> page-$ I; if ($ page> = 1) {$ linkpage. = $ this-> replace ("{$ this-> uri} & page = {$ page}", $ page, false) ;}else {continue ;}$ linkpage. = $ this-> replace ("{$ this-> uri} & page = {$ this-> page}", $ this-> page, true ); for ($ I = 1; $ I <= $ lastlist; $ I ++) {$ page = $ this-> page + $ I; if ($ page <= $ this-> pageNum) {$ linkpage. = $ this-> replace ("{$ this-> uri} & page = {$ page}", $ page, false);} else {break ;}} return $ linkpage;}/*** next page * @ return type */private function next () {$ html = ''; if ($ this-> page <$ this-> pageNum) {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> page + 1), $ this-> config ['Next'], false);} else {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> page + 1), $ this-> config ['Next'], true);} return $ html ;} /*** last page * @ return type */private function last () {$ html = ''; if ($ this-> page = $ this-> pageNum) {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> pageNum), $ this-> config ['last'], true);} else {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> pageNum), $ this-> config ['last'], false);} return $ html ;} /*** jump button * @ return string */private function gopage () {$ html = ''; $ html. =' '; Return $ html ;} /*** template replacement * @ param type $ replace content * @ param type $ result condition * @ return type */private function replace ($ url, $ text, $ result = true) {$ template = ($ result? $ This-> activeTemplate: $ this-> notActiveTemplate); $ html = str_replace ('{url}', $ url, $ template ); $ html = str_replace ('{text}', $ text, $ html); return $ html ;}}

    Section 2 php/2014031173136.html "> php paging class

    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.