Home  >  Article  >  Backend Development  >  Use PHP to implement the code of the previous and next articles_PHP tutorial

Use PHP to implement the code of the previous and next articles_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:15:33858browse

Copy code The code is as follows:

//----Show the previous and next articles Article code START----

$sql_former = "select * from article where id<$id order by id desc "; //SQL statement of the previous article. Note that it is in reverse order, because only the first article is used when returning the result set, not the last article
$sql_later = "select * from article where id>$id "; //Next article sql statement
$queryset_former = mysql_query($sql_former); //Execute sql statement
if(mysql_num_rows($queryset_former)){ //Return the number of records and determine whether it is true, and display the result based on this
$ result = mysql_fetch_array($queryset_former);
echo "Previous post ". $result[title]."
)){
$result = mysql_fetch_array($queryset_later);
echo "Next article ". $result['title ']."
";
} else {echo "There is no next article
";}
?>



http://www.bkjia.com/PHPjc/326111.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326111.htmlTechArticleCopy the code as follows: ?php //----Display the previous and next article code START ---- $sql_former = "select * from article where id$id order by id desc "; // Previous article sql statement...
Statement:
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