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> ";}
?>