Paging details from this page (PHP + mysql) _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Paging details from this page (PHP + mysql ). All the code I sent is original and applied to multiple projects. I often use php + mysql paging code to copy the code as follows :? Php $ perpagenum10; defines how many pieces of code are displayed on each page, all of which are original and applied to multiple projects. you often use php + mysql paging code.

The code is as follows:


$ Perpagenum = 10; // defines the number of entries displayed on each page.
$ Total = mysql_fetch_array (mysql_query ("select count (*) from a"); // query the total number of data records in the database
$ Total = $ total [0]; //
$ Totalpage = ceil ($ Total/$ perpagenum); // go to the house and get the integer
If (! Isset ($ _ GET ['Page']) |! Intval ($ _ GET ['Page']) | $ _ GET ['Page']> $ Totalpage) // Four possible page states
{
$ Page = 1;
}
Else
{
$ Page = $ _ GET ['Page']; // if the preceding conditions are not met, the page value is $ _ GET ['Page']
}
$ Startnum = ($ page-1) * $ perpagenum; // number of start entries
$ SQL = "select * from a order by id limit $ startnum, $ perpagenum"; // query the number of required entries
Echo $ SQL ."
";
$ Rs = mysql_query ($ SQL );
$ Contents = mysql_fetch_array ($ rs );
If ($ total) if $ total is not empty, execute the following statement:
{
Do
{
$ Id = $ contents ['id'];
$ Name = $ contents ['name'];
?>








Id:

Name:


}
While ($ contents = mysql_fetch_array ($ rs); // do... while
$ Per = $ page-1; // Previous page
$ Next = $ page + 1; // next page
Echo" A Total of ". $ Total." records, each page ". $ perpagenum.", Total ". $ Totalpage." page ";
If ($ page! = 1)
{
Echo "homepage ";
Echo "previous page ";
}
If ($ page! = $ Totalpage)
{
Echo "next page ";
Echo "last page ";
}
}
Else outputs No message if $ total is null
{
Echo" No message ";
}
?>

Ghost. I often use php + mysql paging code as follows :? Php $ perpagenum = 10; // defines the number of entries displayed on each page...

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.