php如何实现上一页下一页的功能 (不是列表
4个回答
展开全部
$id = @$_GET["id"];
$res1 = mysql_query("select * from news where id<".$id." order by id desc limit 1");
if($rs1=mysql_fetch_array($res1))
{
echo "上一篇:<a href='?id='.$rs1["id"]>".$rs1["title"]."</a><br />";
}
else
{
echo "上一篇:<span>没有了</span><br />";
}
$res2 = mysql_query("select * from news where id>".$id." order by id asc limit 1");
if($rs2=mysql_fetch_array($res2))
{
echo "下一篇:<a href='?id='.$rs2["id"]>".$rs2["title"]."</a>";
}
else
{
echo "下一篇:<span>没有了</span>";
}
展开全部
不是列表页,是内容页的话,获取本文档的id,然后上下减1不就可以了,然后数据库调用id,这样就出来了啊,还没明白或者不会再找额吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
header("content-type:text/html;charset=utf-8");
$currentpage = 1;
if(isset($_GET['page']))
$currentpage = $_GET['page'];
//连接数据库
$link = mysql_connect("localhost","root","") or die('连接失败');
mysql_select_db('myschool');
mysql_query('set names utf8');
$sql ="SELECT count(*) as 'count' from student";//查询记录的sql语句
$result = mysql_query($sql);
$arr = mysql_fetch_array($result);
$count = $arr['count'];
$pagesize = 3;
$pages = ceil($count/$pagesize);//共多少页
$prepage = $currentpage -1;
if($prepage<=0)
$prepage=1;
$nextpage = $currentpage+1;
if($nextpage >= $pages){
$nextpage = $pages;
}
$start =($currentpage-1) * $pagesize;//起始位置
$sql = "SELECT * from student limit $start,$pagesize";
echo $sql;
// $sql = "select * from student";
$result = mysql_query($sql);
?>
//html部分
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1">
<tr>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
</tr>
<?php while($arr=mysql_fetch_array($result)){ ?>
<td><?php echo $arr['number']; ?></td>
<td><?php echo $arr['name']; ?></td>
<td><?php echo $arr['sex']; ?></td>
<td><?php echo $arr['age']; ?></td>
</tr>
<?php } ?>
</table>
<a href="<?php echo $_SERVER['PHP_SELF'].'?page='.$prepage; ?>">上一页 </a> <a href="<?php echo $_SERVER['PHP_SELF'].'?page='.$nextpage; ?>">下一页</a>
</body>
</html>
header("content-type:text/html;charset=utf-8");
$currentpage = 1;
if(isset($_GET['page']))
$currentpage = $_GET['page'];
//连接数据库
$link = mysql_connect("localhost","root","") or die('连接失败');
mysql_select_db('myschool');
mysql_query('set names utf8');
$sql ="SELECT count(*) as 'count' from student";//查询记录的sql语句
$result = mysql_query($sql);
$arr = mysql_fetch_array($result);
$count = $arr['count'];
$pagesize = 3;
$pages = ceil($count/$pagesize);//共多少页
$prepage = $currentpage -1;
if($prepage<=0)
$prepage=1;
$nextpage = $currentpage+1;
if($nextpage >= $pages){
$nextpage = $pages;
}
$start =($currentpage-1) * $pagesize;//起始位置
$sql = "SELECT * from student limit $start,$pagesize";
echo $sql;
// $sql = "select * from student";
$result = mysql_query($sql);
?>
//html部分
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1">
<tr>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
</tr>
<?php while($arr=mysql_fetch_array($result)){ ?>
<td><?php echo $arr['number']; ?></td>
<td><?php echo $arr['name']; ?></td>
<td><?php echo $arr['sex']; ?></td>
<td><?php echo $arr['age']; ?></td>
</tr>
<?php } ?>
</table>
<a href="<?php echo $_SERVER['PHP_SELF'].'?page='.$prepage; ?>">上一页 </a> <a href="<?php echo $_SERVER['PHP_SELF'].'?page='.$nextpage; ?>">下一页</a>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请求时带上个当前第几页的参数不就可以实现了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询