PHP Implementation paging: text pagination and digital paging _php tutorial

Source: Internet
Author: User

PHP Implementation paging: text pagination and digital paging


Source: http://www.ido321.com/1086.html

Recently, paging was used in the project. Paging is a feature that is often used, so it is encapsulated in a functional form.

Page split/*** $pageType page Type 1 is the number of page 2 is the text paging * can be $pagetotal, $page, $total and other data as parameters, or in paging as a global variable (recommended) */function paging ($    PageType) {Global $pageTotal, $page, $total;            if ($pageType = = 1) {echo '; Echo
 
 
      '; for ($i =0; $i < $pageTotal; $i + +) {if ($page = = ($i + 1)) { Echo '
    • '. ($i + 1). '
    • '; } else {echo '
    • '. ($i + 1). '
    • '; }} Echo '
'; Echo '; } else if ($pageType = = 2) {echo '; Echo '
    '; Echo '
  • '. $page. ' /'. $pageTotal. ' Page |
  • '; Echo '
  • A total of '. $total. ' A Member |
  • '; First page if ($page = = 1) {echo '
  • Home |
  • '; Echo '
  • Prev |
  • '; } else {//$_server["Script_name"] gets the current script name for easy porting You can also customize constants, constant values and script filenames consistent with Echo '
  • Home |
  • '; Echo '
  • Prev |
  • '; }//Last page if ($page = = $pageTotal) {echo '
  • Next Page |
  • '; Echo '
  • End |
  • '; } else {echo '
  • Next Page |
  • '; Echo '
  • End |
  • '; } Echo '
'; Echo '; }}

Parameter explanation:

$pageTotal is the total number of pages, $page is the current page, $total is the total amount of data obtained from the database;

For simplicity, all parameters are encapsulated

Paging parameter/*** $sql an SQL statement that can get the total number of data * $size shows the number of bars per page */function pageparam ($sql, $size) {//sets all the parameters involved in global variables//$PAG    Estart where does a page start//$total total number of records $page a page $pageTotal total pages Global $pagestart, $pagesize, $total, $page, $pageTotal;    $pagesize = $size;    Get the total number of data $total = Mysql_num_rows (Querydb ($sql));        Error handling, first determine if there is an if (Isset ($_get[' page ')) {//specific page $page = $_get[' page '];        Determines whether it is empty (0 is empty)/less than 0/is a number if (Empty ($page) | | $page < 0 | |!is_numeric ($page)) {$page = 1;  } else {$page = Intval ($page);    Rounding, preventing decimals from appearing}} else {//initialization showing page 1th $page = 1;    }//Database clear 0 if ($total = = 0) {//set to 1 $pageTotal = 1;    } else {//page total number of pages (in a rounding process) $pageTotal = Ceil ($total/$pagesize);    }//pages greater than the total number $total if ($page > $pageTotal) {$page = $pageTotal; }//When the page starts with a record $pagestart = ($page-1) *$pagesize;} 

Parameter explanation:

$pagestart is when a page starts from a record, $pagesize is the number of records displayed per page

In use, call Pageparam First, and then call paging

/***  The first  SQL statement that can fetch the total number of data * The  second  page shows the number of bars */pageparam ("Select userid from User", 2);
 
      

The location of the call is selected according to the situation, and the text is paginated as follows:

 
      

The numbers are paginated as follows:

Style adjusts itself.

Next: Google Maps API shows a small example of the map

http://www.bkjia.com/PHPjc/900030.html www.bkjia.com true http://www.bkjia.com/PHPjc/900030.html techarticle PHP Implementation paging: Text paging and digital paging Source: Http://www.ido321.com/1086.html Recently, paging is used in the project. Paging is a feature that is often used, so ...

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