Page detail from this page worry-free (php+mysql) _php Tutorial

Source: Internet
Author: User
I send the code all for my original, and applied in a number of projects. I often use php+mysql pagination code
Copy CodeThe code is as follows:
$perpagenum = 10;//definition shows several pages per page
$total = Mysql_fetch_array (mysql_query ("SELECT count (*) from a"));//Query the database for the total number of data
$Total = $total [0]; //
$Totalpage = Ceil ($Total/$perpagenum);//upper loft, rounding
if (!isset ($_get[' page ') | |! Intval ($_get[' page ') | | $_get[' page ']> $Totalpage)//page possible four states
{
$page = 1;
}
Else
{
$page =$_get[' page '];//if the above four cases are not met, the value of page is $_get[' page '
}
$startnum = ($page-1) * $PERPAGENUM;//Start bar number
$sql = "SELECT * from a the order by ID limit $startnum, $perpagenum";//query out the required number of bars
echo $sql. "
";
$rs = mysql_query ($sql);
$contents = Mysql_fetch_array ($RS);
if ($total) Execute the following statement if $total is not empty
{
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
echo " Total ". $Total." Records, per page ". $perpagenum." Bar, Total ". $Totalpage." Page ";
if ($page! = 1)
{
echo "Home";
echo "Prev";
}
if ($page! = $Totalpage)
{
echo "Next page";
echo "Last ";
}
}
Else output no message if $total is empty
{
echo " No message ";
}
?>

http://www.bkjia.com/PHPjc/318581.html www.bkjia.com true http://www.bkjia.com/PHPjc/318581.html techarticle I send the code all for my original, and applied in a number of projects. I often use the Php+mysql page code to copy code as follows:? PHP $perpagenum =10;//definition shows a few pages per 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.