Share PHP functions to implement code for numbers and text pagination _ PHP

Source: Internet
Author: User
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.

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.