以下是一个php分页代码:
<?php
if($_REQUEST[id]=="")
{
$strs="Select * From productsinfo where IsShow=1";
$results=mysql_query($strs,$link);
$num=mysql_num_rows($results);
$PageSize=7;//每页显示的数
$totalPage=ceil($num/$PageSize);//总页数
if(empty($_GET["page"]))
{
$page=1;
}
else
{
$page=$_GET["page"];
}
$nowpage=$page; //当前页
$strss="Select * From productsinfo where IsShow=1 Order By ToSort limit ".PageSize*($page-1).",".$PageSize;
$resultss=mysql_query($strss);
$nums=mysql_num_rows($resultss);
?>
<div id="pro-list"><ul>
<?php
for($j=0;$j<$nums;$j++)
{
$row=mysql_fetch_array($resultss);
echo"<li><a><img src='imgfile/".$row["ProSImg"]."'/></a><p><a>".$row["ProName"]."</a></p></li>";
}
?>
<ul></div>
总共:<?php echo $totalPage;?>页
总共有:<?php echo $num;?>产品
每页显示:<?php echo $PageSize;?>产品
<?php
if($page==1)
{
echo"当前页:".$nowpage."  ";
echo"首页 ";
echo"上一页 ";
echo"<a href='?page=".($page+1)."'>下一页</a> ";
echo"<a href='?page=".$totalPage."'>末页</a>";
}
elseif($page==$totalPage)
{
echo"当前页:".$nowpage."  ";
echo"<a href='?page=1'>首页</a> ";
echo"<a href='?page=".($page-1)."'>上一页</a> ";
echo"下一页 ";
echo"末页";
}else
{
echo"当前页:".$nowpage."  ";
echo"<a href='?page=1'>首页</a> ";
echo"<a href='?page=".($page-1)."'>上一页</a> ";
echo"<a href='?page=".($page+1)."'>下一页</a> ";
echo"<a href='?page=".$totalPage."'>末页</a>";
}
}
?>