php下一页
① php,在html中怎样实现分页代码:首页、下一页、上一页、尾页
给你个实例看看吧:
<?php
include("conn/conn.php");
$pagesize=2;
$url=$_SERVER["REQUEST_URI"];
$url=parse_url($url);
$url=$url['path'];
$sql="select * from tb_info ";
$query=mysql_query($sql);
//print_r($query);
$rows=mysql_num_rows($query);
$pageval=1;
$page=($pageval-1)*$pagesize;
if(@$_GET['page']){
$pageval=$_GET['page'];
if ($pageval<=0){
$pageval=1;
}
$page=($pageval-1)*$pagesize;
}
echo "共 $rows 条";
$pagenum=ceil($rows/$pagesize);
for($i=1;$i<=$pagenum;$i++){
if ($pageval==$i){
echo "<font color=#ff0000>".$i."</font> ";
}else{
echo "<a href=$url?page=".$i.">$i</a> ";
}
}
if($rows>$pagesize){
if ($pageval==1){
echo "<a href=$url?page=".($pageval+1).">下一页</a>";
}else{
if ($pageval*$pagesize>=$rows){
echo "<a href=$url?page=".($pageval-1).">上一页</a>";
}else{
echo "<a href=$url?page=".($pageval-1).">上一页</a> "."<a href=$url?page=".($pageval+1).">下一页</a>";
}
}
}
echo "<br>";
$sqli="select * from tb_info limit $page,$pagesize";
$que=mysql_query($sqli);
while($row=mysql_fetch_array($que)){
echo $row['type']."<br>".$row['content']."<br>";
echo str_repeat("_",40)."<br>";
}
?>