PHP paging: Text paging and numeric Paging

Source: Internet
Author: User
Source: www.ido321.com__6.html recently. pagination is required in the project. The paging function is often used. Therefore, it is encapsulated as a function. Paging and packaging ** $ pageType paging type 1: Digital paging 2: Text paging * data such as $ pageTotal, $ page, and $ total can be passed as parameters,

Source: http://www.ido321.com/1086.html recently, pagination is used in projects. The paging function is often used. Therefore, it is encapsulated as a function. // Paging/***** $ pageType paging type 1: Digital paging 2: Text paging * You can pass $ pageTotal, $ page, $ total, and other data as parameters,

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

Recently, pagination is required in the project. The paging function is often used. Therefore, it is encapsulated as a function.

// Paging/***** $ pageType paging type 1: Digital paging 2: Text paging * You can pass $ pageTotal, $ page, $ total, and other data as parameters, or use 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). '"class =" selected ">'. ($ I + 1 ).'
  • ';} Else {echo'
  • . ($ I + 1). '">'. ($ I + 1 ).'
  • ';} Echo'
'; Echo'

';} Else if ($ pageType = 2) {echo'

'; Echo'

    '; Echo'
  • '. $ Page.'/'. $ pageTotal.' page |
  • '; Echo'
  • Total'. $ Total .'Members |
  • '; // The first page if ($ page = 1) {echo'
  • Homepage |
  • '; Echo;} else {// $ _ SERVER ["SCRIPT_NAME"] Get the name of the current script to facilitate transplantation // You can also customize constants, constant Value and script file name are consistent echo'
  • . $ _ SERVER ["SCRIPT_NAME"]. '"> homepage |
  • '; Echo'
  • . $ _ SERVER ["SCRIPT_NAME"]. '? Page = '. ($ page-1).;} // The last page if ($ page = $ pageTotal) {echo; echo'
  • Last page |
  • ';} Else {echo'
  • . $ _ SERVER ["SCRIPT_NAME"]. '? Page = '. ($ page + 1).; echo'
  • . $ _ SERVER ["SCRIPT_NAME"]. '? Page = '. ($ pageTotal).' "> last page |
  • ';} Echo'
'; Echo'

';}}

Parameter description:

$ PageTotal indicates the total number of pages, $ page indicates the current page, and $ total indicates the total number of data retrieved from the database;

To simplify the process, encapsulate all parameters.

// Paging parameter package/*** $ SQL can be used to obtain the total number of data in an SQL statement * $ size the number of entries displayed on each page */function pageParam ($ SQL, $ size) {// set global variables for all involved parameters // $ where to start a page of pagestart // $ total number of records $ page a page $ total pageTotal pages global $ pagestart, $ pagesize, $ total, $ page, $ pageTotal; $ pagesize = $ size; // total number of Retrieved Data $ total = mysql_num_rows (queryDB ($ SQL); // error handling, first, determine whether there is an if (isset ($ _ GET ['page']) {// a specific page $ page = $ _ GET ['page']; // determine whether it is empty (0 is empty)/less than 0/whether it is a number if (empty ($ pag E) | $ page <0 |! Is_numeric ($ page) {$ page = 1;} else {$ page = intval ($ page); // integer, prevent decimal occurrence} else {// initialize display 1st page $ page = 1;} // CLEAR database if ($ total = 0) {// set to 1 $ pageTotal = 1;} total number of else {// pages (one-to-one integer) $ pageTotal = ceil ($ total/$ pagesize );} // The page number is greater than the total page number $ total if ($ page> $ pageTotal) {$ page = $ pageTotal ;} // when the page starts from a record $ pagestart = ($ page-1) * $ pagesize ;}

Parameter description:

$ Pagestart: When a page starts from a record, $ pagesize indicates the number of records displayed on each page.

In use, call pageParam first, and then call paging

/*** The first SQL statement that can obtain the total number of data * The number of entries displayed on the second page */pageParam ("select userid from user", 2 );

     

Select the call location based on the actual situation. The text page is as follows:

     

The number page is as follows:

Adjust the style.

Small examples of Map Display by Google Maps API

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.