Use PHP to implement the code of the previous and next articles

Source: Internet
Author: User

Copy codeThe Code is as follows: <? Php
// ---- Display the code START in the previous and next articles ----

$ SQL _former = "select * from article where id <$ id order by id desc"; // The SQL statement of the previous article. Note that it is inverted because only the first article is used when the result set is returned, instead of the last article.
$ SQL _later = "select * from article where id> $ id"; // The SQL statement in the next article
$ Queryset_former = mysql_query ($ SQL _former); // execute an SQL statement
If (mysql_num_rows ($ queryset_former) {// returns the number of records and determines whether it is true. Based on this, the result is displayed.
$ Result = mysql_fetch_array ($ queryset_former );
Echo "previous article <a href = 'index. php? Id = $ result [id] '> ". $ result [title]." </a> <br> ";
} Else {echo "no more in the previous article <br> ";}

$ Queryset_later = mysql_query ($ SQL _later );
If (mysql_num_rows ($ queryset_later )){
$ Result = mysql_fetch_array ($ queryset_later );
Echo "next <a href = 'index. php? Id = $ result [id] '> ". $ result ['title']." </a> <br> ";
} Else {echo "the next article is missing <br> ";}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.