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