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>";
}
?>
<?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>";
}
?>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询