Home > Backend Development > PHP Tutorial > Detailed explanation of php+mysql paging code_PHP tutorial

Detailed explanation of php+mysql paging code_PHP tutorial

WBOY
Release: 2016-07-21 15:53:06
Original
1065 people have browsed it

Copy code The code is as follows:

$perpagenum = 10;//Define each page display Several pieces
$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 and 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 four conditions are not met, the value of page is $_GET['page']
}
$startnum = ($page-1)*$perpagenum ;//Start number of items 
$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 statement 🎜>                                             "center">                                                                        > ; 
 
 name: 
  
  
 
                                                                           //Previous page
$next = $page + 1;//Next page
echo "
There are ".$Total." records, and each page has ".$perpagenum." records, Total ".$Totalpage." pages ";                                                                         Home";
echo " Previous page ";
}
if($page != $Totalpage)
{
echo " Next page";
echo " Last page
";
}
}
else If $total is empty, No message will be output
{
echo "
No message< ;/center>";
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318799.htmlTechArticleCopy the code as follows: ?php $perpagenum=10;//Define how many items are displayed on each page $total=mysql_fetch_array (mysql_query("selectcount(*)froma"));//Query how many pieces of data there are in the database...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template