This article mainly introduces the code for implementing the number and text paging using PHP functions, defines the paging function _ paging, and wraps the code in the core function library, for more information, see the next article. This article mainly uses PHP functions to implement pagination of numbers and text.
/***** @ Param $ _ SQL * @ param $ _ size */function _ page ($ _ SQL, $ _ size) {// obtain all the variables in the table. externally, you can access global $ _ page, $ _ pagesize, $ _ pagenum, $ _ pageabsolute, $ _ num; if (isset ($ _ GET ['Page']) {$ _ page = $ _ GET ['Page']; if (empty ($ _ page) | $ _ page <0 |! Is_numeric ($ _ page) {$ _ page = 1;} else {$ _ page = intval ($ _ page) ;}} else {$ _ page = 1 ;} $ _ pagesize = $ _ size; $ _ num = _ num_rows (_ query ($ _ SQL); if ($ _ num = 0) {$ _ pageabsolute = 1;} else {$ _ pageabsolute = ceil ($ _ num/$ _ pagesize);} if ($ _ page> $ _ pageabsolute) {$ _ page =$ _ pageabsolute;} $ _ pagenum = ($ _ page-1) * $ _ pagesize ;} /*** _ paging function * @ param $ _ type * @ return returns pagination */function _ paging ($ _ type) {global $ _ page, $ _ pageabsolute, $ _ num; if ($ _ type = 1) {echo''; Echo'
'; For ($ I = 0; $ I <$ _ pageabsolute; $ I ++) {if ($ _ page = ($ I + 1) {echo'
- '. ($ I + 1 ).'
';} Else {echo'
- '. ($ I + 1 ).'
';} Echo'
'; Echo'
';} Elseif ($ _ type = 2) {echo'
'; Echo'
'; Echo'
- '. $ _ Page.'/'. $ _ pageabsolute.' page |
'; Echo'
- Total'. $ _ Num .'Members |
'; If ($ _ page = 1) {echo'
- Homepage |
'; Echo'
- |
'; Echo'
- Last page
';} Else {echo'
- Next Page |
'; Echo'
- Last page
';} Echo'
'; Echo'
';}}
Wrap the above code glob. funic. php in the core function library
Then, you only need to call the following functions in the file:
The code is as follows:
<? Php}
// _ Pageing function call page, 1 | 2, 1 indicates the number page, 2 indicates the text page
_ Paging (2 );
?>
The above is all the content of the code for implementing numbers and text pagination using php functions. I hope you will like it.