简单的PHP+Mysql查询上一篇和下一篇文章实例,并输出上一篇和下一篇文章的标题和链接,适合新手学习
获取当前浏览文章id:
$id = isset($_GET['id']) > 0 ? intval($_GET['id']) : "";
下一篇文章:
$query = mysql_query("SELECT id,title FROM article WHERE id>'$id' ORDER BY id ASC LIMIT 1");
$next = mysql_fetch_array($query);
上一篇文章:
$query = mysql_query("SELECT id,title FROM article WHERE id <'$id' ORDER BY id DESC LIMIT 1");
$prev = mysql_fetch_array($query);
输出:
<div class="page_nav clearfix">
<div title="下一篇" class="next_page">
<a href="?id=<?php echo $next['id']; ?>"><?php echo $next['title']; ?></a>
</div>
<div title="上一篇" class="pre_page">
<a href="?id=<?php echo $prev['id']; ?>"><?php echo $prev['title']; ?></a>
</div>
</div>
本文转自:https://www.sucaihuo.com/php/436.html 转载请注明出处!