Home > Backend Development > PHP Tutorial > 用PHP实现 上一篇、下一篇的代码_PHP

用PHP实现 上一篇、下一篇的代码_PHP

WBOY
Release: 2016-06-01 12:08:50
Original
1170 people have browsed it
复制代码 代码如下:
//----显示上一篇、下一篇文章代码 START----

$sql_former = "select * from article where id$sql_later = "select * from article where id>$id "; //下一篇文章sql语句
$queryset_former = mysql_query($sql_former); //执行sql语句
if(mysql_num_rows($queryset_former)){ //返回记录数,并判断是否为真,以此为依据显示结果
$result = mysql_fetch_array($queryset_former);
echo "上一篇 ". $result[title]."
";
} else {echo "上一篇 没有了
";}

$queryset_later = mysql_query($sql_later);
if(mysql_num_rows($queryset_later)){
$result = mysql_fetch_array($queryset_later);
echo "下一篇 ". $result['title']."
";
} else {echo "下一篇 没有了
";}
?>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template