Detailed explanation of paging, worry-free pagination (PHP+mysql)_PHP tutorial

WBOY
Release: 2016-07-21 15:53:55
Original
700 people have browsed it

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 items 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];                                                       !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
$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
{
do
{
$id = $contents['id'];
$name = $contents ['name'];
?>



($rs));//do....while
$per = $page - 1;//Previous page
$next = $page + 1;//Next page
echo "
There are ".$Total." records in total, ".$perpagenum." records in each page, and a total of ".$Totalpage." pages ";
if($page != 1)
{
echo "Homepage";
echo " Previous page";
}
if($page != $Totalpage)
{
echo " Next page";
echo " Last page
";
}
}
else if $total is empty, output No message
{
echo "
No message
";
}
?>





http://www.bkjia.com/PHPjc/318581.html

www.bkjia.com

true
http: //www.bkjia.com/PHPjc/318581.html

TechArticle

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
id:
< ;?php echo $id;?>
                                         $name;?>