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

  • 2020-05-26 07:53:45
  • OfStack

 
<?php 
//---- On the display 1 Under the article, 1 Article code  START---- 

$sql_former = "select * from article where id<$id order by id desc "; // on 1 article sql Statements. Note that it is in reverse order, because only the order is used when returning the result set 1 An article, not the last 1 article  
$sql_later = "select * from article where id>$id "; // Under the 1 article sql statements  
$queryset_former = mysql_query($sql_former); // perform sql statements  
if(mysql_num_rows($queryset_former)){ // Returns the number of records and determines whether it is true, and displays the result accordingly  
$result = mysql_fetch_array($queryset_former); 
echo " on 1 article  <a href='index.php?id=$result[id]'> ". $result[title]." </a><br>"; 
} else {echo " on 1 article   Without the <br>";} 

$queryset_later = mysql_query($sql_later); 
if(mysql_num_rows($queryset_later)){ 
$result = mysql_fetch_array($queryset_later); 
echo " Under the 1 article  <a href='index.php?id=$result[id]'> ". $result['title']."</a><br>"; 
} else {echo " Under the 1 article   Without the <br>";} 
?> 

Related articles: