Php+mysql pagination code detailed _php skill

Source: Internet
Author: User

Copy Code code as follows:

<?php
$perpagenum = 10;//defines a few per-page display
$total = Mysql_fetch_array (mysql_query ("SELECT count (*) from a");//How many data are there in the query database
$Total = $total [0]; //
$Totalpage = Ceil ($Total/$perpagenum);/upper house, 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 conditions are not met, the page value is $_get[' page ']
}
$startnum = ($page-1) * $perpagenum//number of start bars
$sql = "SELECT * FROM (a) Order by ID limit $startnum, $perpagenum"//query out required number of bars
echo $sql. "
";
$rs = mysql_query ($sql);
$contents = Mysql_fetch_array ($RS);
if ($total) executes the following statement if $total is not empty
{
Todo
{
$id = $contents [' id '];
$name = $contents [' name '];
?>
<table border= "0" align= "center" >
<tr>
<td>id:
<?php echo $id;? >
</td>
</tr>
<tr>
<td>name:
<?php echo $name;? >
</td>
</tr>
</table>
<?php
}
while ($contents = Mysql_fetch_array ($rs));//do....while
$per = $page -1;//Previous page
$next = $page + 1;//Next page
echo "<center> common". $Total. " Record, per page ". $perpagenum." , $Totalpage. " Page ";
if ($page!= 1)
{
echo "<a href= '". $_server[' php_self '. "' > Home </a> ";
echo "<a href= '". $_server[' php_self '. Page= '. $per. "' > Prev </a> ";
}
if ($page!= $Totalpage)
{
echo "<a href= '". $_server[' php_self '. Page= '. $next. "' > next page </a> ";
echo "<a href= '". $_server[' php_self '. Page= '. $Totalpage. "' > Last </a></center> ";
}
}
Else output no message if $total is empty
{
echo "<center>no message</center>";
}
?>

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.