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>";
}
?>