Share PHP functions to implement digital and text paging code _php instances

Source: Internet
Author: User
This article is mainly to use PHP functions to achieve digital and text paging, the implementation of the step is not wordy, directly on the code

/** * * @param $_sql * @param $_size */function _page ($_sql,$_size) {//Remove all variables inside, external access to global $_page,$_pagesize,$_p  Agenum,$_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 Paging function * @param $_type * @return back to 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 '
    • A total of '. $_num ' Members |
    • '; if ($_page = = 1) {echo '
    • Home |
    • '; Echo '
    • Prev |
    • '; } else {echo '
    • Home |
    • '; Echo '
    • Prev |
    • '; } if ($_page = = $_pageabsolute) {echo '
    • Next Page |
    • '; Echo '
    • Last
    • '; } else {echo '
    • Next Page |
    • '; Echo '
    • Last
    • '; } Echo '
'; Echo '; }}

Wrap the above code in the core library glob.funic.php

You can then simply call the following function in the file:

Copy the Code code as follows:
<?php}
_pageing function call paging, 1|2,1 for digital paging, 2 for text paging
_paging (2);
?>

The above is the PHP function to achieve digital and text pagination code of the entire content, I hope you can like.

  • 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.