Php paging function sample code, php paging code implementation method, paging sample code _ PHP Tutorial

Source: Internet
Author: User
Php paging function sample code, php paging code implementation method, and paging sample code. Php paging function sample code, php paging code implementation method, paging sample code php paging function sample code to share a php paging function code. using this function to implement paging code is good. Php paging function sample code, php paging code implementation method, paging Sample code
Php paging function Sample code

Share a php paging function code example. using this function to implement paging code is good.

Code, php paging function.

 $ TotalRecord "; if ($ lastpg <= 1) return false; // if only one page exists, if ($ page! = 1) $ pagecon. = "homepage"; else $ pagecon. = "homepage"; if ($ prepg) $ pagecon. = "previous page"; else $ pagecon. = "previous page"; if ($ nextpg) $ pagecon. = "back page"; else $ pagecon. = "back page"; if ($ page! = $ Lastpg) $ pagecon. = "Last page"; else $ pagecon. = "Last page"; # drop-down navigation list, listing all page numbers cyclically $ pagecon. ="\ N "; for ($ I = 1; $ I <= $ lastpg; $ I ++) {if ($ I = $ page) $ pagecon. ="$ I\ N "; else $ pagecon. ="$ I\ N ";}$ pagecon. ="Page, total $ lastpg page ";}} else die ('pagedivide () function with the same name already exists! ');?>

Articles you may be interested in:
Simple paging code for entry-level PHP
Detailed explanation of PHP paging code (with instance attached)
Php simple paging code example
Php paging class with multiple paging methods
A handy php paging class
Example of simple php paging code
A Practical php paging class
A quick and easy-to-use php paging class


PHP paging code

Let me give you a class. it's very simple,
// Paging function
Class pg {
Function genpage (& $ SQL, $ page_size = 2)
{
Global $ prepage, $ nextpage, $ pages, $ sums; // out param
$ Page = $ _ GET ["page"];
$ Eachpage = $ page_size;
$ Pagesql = strstr ($ SQL, "from ");
$ Pagesql = "select count (*) as ids". $ pagesql;
$ Result = mysql_query ($ pagesql) or die (mysql_error ());
If ($ rs = mysql_fetch_array ($ result) $ sums = $ rs [0];
$ Pages = ceil ($ sums-0.5)/$ eachpage)-1;
$ Pages = $ pages> = 0? $ Pages: 0;
$ Prepage = ($ page> 0 )? $ Page-1: 0;
$ Nextpage = ($ page <$ pages )? $ Page + 1: $ pages;
$ Startpos = $ page * $ eachpage;
$ SQL. = "limit $ startpos, $ eachpage ";
}
Function showpage ()
{
Global $ page, $ pages, $ prepage, $ nextpage, $ queryString;
$ QueryString = $ _ SERVER ['query _ string'];
If (preg_match ("/page/", $ queryString )){
$ QueryString = strstr ($ queryString ,"&");
} Else {
$ QueryString = "&". $ queryString;
}

$ Shownum = 10/2;
$ Startpage = ($ page >=$ shownum )? $ Page-$ shownum: 0;
$ Endpage = ($ page + $ shownum <= $ pages )? $ Page + $ shownum: $ pages;
$ Xs = "";
$ Xs. = "total". ($ pages + 1). "page :";
If ($ page> 0) $ xs. = "homepage </a> ";
If ($ startpage> 0)
$ Xs. = "...? </A>... the remaining full text>

PHP paging code

Include ("connection. php ");
$ PerNumber = 10; // number of records displayed on each page
$ Page = $ _ GET ['Page']; // Obtain the current page value.
$ Count = mysql_query ("select count (*) from user"); // obtain the total number of records
$ Rs = mysql_fetch_array ($ count );
$ TotalNumber = $ rs [0];
$ TotalPage = ceil ($ totalNumber/$ perNumber); // calculate the total number of pages
If (! Isset ($ page )){
$ Page = 1;
} // If no value exists, 1 is assigned.
$ StartCount = ($ page-1) * $ perNumber; // start by page. calculate the start record based on this method.
$ Result = mysql_query ("select * from user limit $ startCount, $ perNumber"); // calculate the start record and number of records based on the previous calculation.
While ($ row = mysql_fetch_array ($ result )){
Echo "user_id:". $ row [0]."
";
Echo "username:". $ row [1]."
"; // Display the database content
}
If ($ page! = 1) {// The page number is not equal to 1
?>
"> Previous Page </a>
}
For ($ I = 1; $ I <= $ totalPage; $ I ++) {// The page is displayed cyclically.
?>
"> </A>
}
If ($ page <$ totalPage) {// if the page is smaller than the total number of pages, the next page link is displayed.
?>
"> Next page </a>
}
?>
======================================

This is very simple... and I wrote comments... I don't know if it doesn't suit you ..

Example code of the pagination function in php shares the code of a php paging function. using this function to implement paging code is good ....

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.