PHP paging functions are similar to Google paging PHP code
/*** Paging function ** @ param int $ total page number * @ param int $ pagesize the number of pages on each page * @ param string $ name of the page variable in the pkey url * @ param string $ basic url, the {page} will be replaced with the page number * dependent function request_uri httpInt */function page ($ total, $ pagesize = 10, $ pkey = 'p', $ url = null) {$ a_num = 10; $ first = 'homepage'; $ last = 'Last page'; $ pre = 'previous page'; $ next = 'next page '; $ a_num = $ a_num % 2 = 0? $ A_num + 1: $ a_num; if (! $ Url) {$ url = preg_replace ("/&? {$ Pkey} = [^ &] {0,}/",'', request_uri (); $ url = strpos ($ url ,'? ') = FALSE? $ Url .'? '. $ Pkey. '= {page}': $ url. '&'. $ pkey. '= {page}';} $ pages = ceil ($ total/$ pagesize); $ curpage = httpInt ($ pkey, false, 1 ); $ curpage = $ curpage> $ pages | $ curpage <= 0? 1: $ curpage; # set the current page to 1 $ body = ''; $ prefix =''; $ subfix = ''; $ start = $ curpage-($ a_num-1) /2; # start Page $ end = $ curpage + ($ a_num-1)/2; # end page $ start = $ start <= 0? 1: $ start; # starting page out-of-range correction $ end = $ end> $ pages? $ Pages: $ end; # end Page out-of-range correction if ($ pages >=$ a_num) {# total pages greater than display pages if ($ curpage <= ($ a_num-1)/2) {$ end = $ a_num;} // if ($ end-$ curpage <= ($ a_num-1)/2) on the left half of the current page) {$ start-= 5-($ end-$ curpage);} // left side of the current page in the right half} for ($ I = $ start; $ I <= $ end; $ I ++) {if ($ I ==$ curpage) {$ body. =''. $ I .'';} Else {$ body. = ''. $ I.'' ;}}$ prefix = ($ curpage = 1? '':''. $ First. ''. $ pre.''); $ subfix = ($ curpage = $ pages? '':''. $ Next. ''. $ last. ''); $ info =" page {$ curpage}/{$ pages} "; $ go = 'script function ekup () {if (event. keyCode = 13) {clkyup () ;}} function clkyup () {if (! /\ D +/. test (document. getElementById (\ 'gsd09fhas9d \ '). value) {alert (\' enter the page number! \ '); Return;}; location = \''. $ url. '\'. replace (// \ {page \}/, document. getElementById (\ 'gsd09fhas9d \'). value);} scriptGo to '; return $ prefix. $ body. $ subfix. $ info. $ go;}/*** description: a general solution for getting the value of _ SERVER ['request _ URI '] */function request_uri () {if (isset ($ _ SERVER ['request _ URI ']) {$ uri = $ _ SERVER ['request _ URI'];} else {if (isset ($ _ SERVER ['argv']) {$ uri = $ _ SERVER ['php _ SELF ']. '? '. $ _ SERVER ['argv'] [0];} else {$ uri = $ _ SERVER ['php _ SELF']. '? '. $ _ SERVER ['query _ string'] ;}return $ uri ;} /*** get the integer passed by HTTP * @ param string $ key parameter name * @ param bool $ ispost adopts the POST transmission method, which is true by default. http://blog.ddian.cn * @ Return Integer. the default value is $ default */function httpInt ($ key, $ ispost = true, $ default = 0) {if ($ ispost) {if (isset ($ _ POST [$ key]) {if (empty ($ _ POST [$ key]) {return $ default ;} else {$ val = trim ($ _ POST [$ key]); if (preg_match ("/^ \-? \ D + $/", $ val) return intval ($ val); else return $ default ;}} else {return $ default ;}} else {if (isset ($ _ GET [$ key]) {if (empty ($ _ GET [$ key]) {return $ default ;} else {$ val = trim ($ _ GET [$ key]); if (preg_match ("/^ \-? \ D + $/", $ val) {return intval ($ val) ;}else {return $ default ;}} else {return $ default ;}}}