PHP paging function _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
The paging function of PHP .? Php creates a database connection $ linkmysql_connect (localhost, root, wyh7ye); obtain the current page number mysql_select_db (test, $ link ); if (isset ($ _ GET [page])... {$ pageintval ($ _ GET [page]);} e // Establish a database connection
$ Link = mysql_connect ("localhost", "root", "wyh7ye ");
; // Obtain the current page number
Mysql_select_db ("test", $ link );
If (isset ($ _ GET ['Page'])... {
$ Page = intval ($ _ GET ['Page']);
}
Else ...{
$ Page = 1;
}
// Number of pages per page
$ Page_size = 4;
// Obtain the total data volume
$ SQL = "select * from user ";
$ Result = mysql_query ($ SQL, $ link );
While ($ row = mysql_fetch_array ($ result ))...{
$ I = $ I + 1;
}
$ Amount = $ I;
// Count the total number of pages
If ($ amount )...{
If ($ amount <$ page_size)... {$ page_count = 1 ;}// if the total data volume is less than $ PageSize, there is only one page
If ($ amount % $ page_size)... {// Retrieve the total data volume divided by the remainder of each page
$ Page_count = (int) ($ amount/$ page_size) + 1; // if there is a remainder, the number of pages equals the total data volume divided by the result of each page number and then adds one
} Else ...{
$ Page_count = $ amount/$ page_size; // if there is no remainder, the number of pages equals the total data volume divided by the result of each page
}
}
Else ...{
$ Page_count = 0;
}
// Obtain data and return results in two-dimensional array format
If ($ amount )...{
$ SQL = "select * from user order by id desc limit". ($ page-1) * $ page_size. ", $ page_size ";
$ Result = mysql_query ($ SQL, $ link );
While ($ row = mysql_fetch_array ($ result ))...{
?>








}
}
// Flip link
$ Page_string = "";
If ($ page = 1 )...{
$ Page_string. = "first page | previous page | ";
}
Else ...{
$ Page_string. = "first page | href =? Page = ". ($ page-1)."> Previous page | ";
}
If ($ page = $ page_count) | ($ page_count = 0 ))...{
$ Page_string. = "next page | last page ";
}
Else ...{
$ Page_string. = "next page | last page ";
}
Echo $ page_string;
?>

Http://www.bkjia.com/PHPjc/318270.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318270.htmlTechArticle? Php // create a database connection $ link = mysql_connect (localhost, root, wyh7ye); // Obtain the current page number mysql_select_db (test, $ link ); if (isset ($ _ GET [page])... {$ page = intval ($ _ GET [page]);} e...

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.