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 '];
?>
}
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 ";
}
?>
The above describes the SQL paging php+mysql page code in detail, including the content of SQL paging, I hope that the PHP tutorial interested in a friend helpful.