<?php
$cid = $id;//是你当前文章的编号
$classId = get_father($id);
$sql ="select * from news where id>$cid and classId=$classId order by id asc limit 0,1"; //上一篇文章
$result = mysql_query( $sql );
if( mysql_num_rows( $result ) )
{
$rs = mysql_fetch_array( $result );
echo "<a href=news.php?id=".$rs[id]."><strong>上一篇:</strong>".$rs[title]."</a><br>";
}
else
{
echo "<a href=''>上一篇:没有了</a><br>";
}
$sql1 ="select * from news where id<$cid and classId=$classId order by id desc limit 0,1";//下一篇文章
$result1= mysql_query( $sql1 );
if( mysql_num_rows( $result1 ) )
{
$rs1= mysql_fetch_array( $result1 );
echo "<span><a href=news.php?id=".$rs1[id]."><strong>下一篇:</strong>".$rs1[title]."</a></span>";
}
else
{
echo "<span>下一篇:没有了</span>";
}
?>
转载于:https://blog.51cto.com/wangliwen/1434413