PHP implementation previous and next code _ PHP Tutorial

Source: Internet
Author: User
PHP implements the code of the previous and next articles. Code :? Php ---- show the code of the previous and next articles START ---- $ SQL _formerselect * fromarticlewhereid $ idorderbyiddesc; SQL statement of the previous article. Note that it is in reverse order, because

Code:

  1. // ---- Display the code START in the previous and next articles ----
  2. $ 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.
  3. $ SQL _later = "select * from article where id> $ id"; // the SQL statement in the next article
  4. $ Queryset_former = mysql_query ($ SQL _former); // execute an SQL statement
  5. If (mysql_num_rows ($ queryset_former) {// returns the number of records and determines whether it is true. Based on this, the result is displayed.
  6. $ Result = mysql_fetch_array ($ queryset_former );
  7. Echo "previous". $ result [title]."
    ";
  8. } Else {echo "no more in the previous article
    ";}
  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". $ result ['title']."
    ";
  14. } Else {echo "the next article is missing
    ";}
  15. ?>

Why :? Php // ---- show the code of the previous and next articles START ---- $ SQL _former = "select * fromarticlewhereid $ idorderbyiddesc"; // the SQL statement of the previous article. Note that it is in reverse order, because...

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.