Home > php教程 > php手册 > body text

PHP实现 上一篇、下一篇的代码

WBOY
Release: 2016-06-13 09:43:57
Original
1014 people have browsed it

代码:

  1. //----显示上一篇、下一篇文章代码 START----   
  2.   
  3. $sql_former = "select * from article where id; //上一篇文章sql语句。注意是倒序,因为返回结果集时只用了第一篇文章,而不是最后一篇文章   
  4. $sql_later = "select * from article where id>$id "//下一篇文章sql语句   
  5. $queryset_former = mysql_query($sql_former); //执行sql语句   
  6. if(mysql_num_rows($queryset_former)){ //返回记录数,并判断是否为真,以此为依据显示结果   
  7. $result = mysql_fetch_array($queryset_former);   
  8. echo "上一篇  "$result[title].
    "
    ;   
  9. else {echo "上一篇 没有了
    "
    ;}   
  10.   // www.jbxue.com
  11. $queryset_later = mysql_query($sql_later);   
  12. if(mysql_num_rows($queryset_later)){   
  13. $result = mysql_fetch_array($queryset_later);   
  14. echo "下一篇  "$result['title']."
    "
    ;   
  15. else {echo "下一篇 没有了
    "
    ;}   
  16. ?>   
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template