Home >Backend Development >PHP Tutorial >Detailed explanation of paging, worry-free paging with PHP+mysql
All the codes I posted are original and have been used in multiple projects. I often use php+mysql paging code
Copy the code The code is as follows:
$perpagenum = 10;/ /Define how many pieces of data are displayed on each page
$total = mysql_fetch_array(mysql_query("select count(*) from a"));//Query how many pieces of data there are in the database
$Total = $total[0]; $Totalpage = ceil($Total/$perpagenum);//Round up, round
if(!isset($_GET['page'])||!intval($_GET['page'])||$_GET ['page']>$Totalpage)//Four possible states of page
{
$page=1;
}
else
{
$page=$_GET['page'];//If the above is not met In four cases, the value of page is $_GET['page']
}
$startnum = ($page-1)*$perpagenum;//Starting number
$sql = "select * from a order by id limit $startnum,$perpagenum";//Query the required number of items
echo $sql."
";
$rs = mysql_query($sql);
$contents = mysql_fetch_array($rs);
if($total) If $ Total is not empty, execute the following statements
{
Do
{
$ ID = $ Contents ['ID'];
$ Name = $ Contents ['name'];
? "0" align="center">