Home > Backend Development > PHP Tutorial > PHP implementation code for previous and next articles_PHP tutorial

PHP implementation code for previous and next articles_PHP tutorial

WBOY
Release: 2016-07-13 10:39:41
Original
928 people have browsed it

Code:

  1. //----Display the previous and next article codes START----
  2. $sql_former = "select * from article where id<$id order by id desc "; //Previous article sql statement. Note that it is in reverse order, because only the first article is used when returning the result set, not the last article
  3. $sql_later = "select * from article where id>$id "; //Next article sql statement
  4. $queryset_former = mysql_query($sql_former); //Execute sql statement
  5. if(mysql_num_rows($queryset_former)){ //Return the number of records and determine whether it is true, and display the results based on this
  6. $result = mysql_fetch_array($queryset_former);
  7. echo "Previous post ". $result [title]."
    "
    ;
  8. } else {echo "Previous post No more
    "
    ;} 
  9. // www.jbxue.com
  10. $queryset_later = mysql_query($sql_later);
  11. if(mysql_num_rows($queryset_later)){
  12. $result = mysql_fetch_array($queryset_later);
  13. echo "Next article ". $result ['title']."
    "
  14. } else {echo "Next article No more
    "
    ;}
  15. ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/729837.htmlTechArticleCode: ?php //----Display previous and next article code START--- - $sql_former = "select*fromarticlewhereid$idorderbyiddesc"; //SQL statement of the previous article. Note that it is in reverse order, because...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template