The pagination effects of numbers and text in PHP self-training projects are implemented in functions

Source: Internet
Author: User
: This article describes how to implement pagination of numbers and text in PHP self-training projects in functions. For more information about PHP tutorials, see.

/***** @ 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). '">'. ($ I + 1 ).'
  • ';} Else {echo'
  • $ I + 1). '">'. ($ I + 1 ).'
  • ';} Echo'
'; Echo'

';} Elseif ($ _ type = 2) {echo'

'; Echo'

    '; Echo'
  • '. $ _ Page.'/'. $ _ pageabsolute.' page |
  • '; Echo'
  • Total'. $ _ Num .'Members |
  • '; If ($ _ page = 1) {echo'
  • Homepage |
  • '; Echo'
  • Previous Page |
  • ';} Else {echo'
  • Homepage |
  • '; Echo'
  • $ _ Page-1). '"> Previous page |
  • ';} If ($ _ page ==$ _ pageabsolute) {echo'
  • Next Page |
  • '; Echo'
  • Last page
  • ';} Else {echo'
  • $ _ Page + 1). '"> Next page |
  • '; Echo'
  • $ _ Pageabsolute. '"> 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:

// _ Pageing function call page, 1 | 2, 1 indicates the number page, 2 indicates the text page
_ Paging (2 );
?>

The above introduces the implementation of the pagination effects of numbers and text in PHP self-training projects in functions, including some content, and hope to help friends who are interested in PHP tutorials.

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.