假设当前查看的新闻编号为14,是cateid=1的国际新闻
下一页
select * from newsTable where id < 14 and catid = 1 limit 1
上一页
select * from newsTable where id < 14 and catid = 1 limit 1
下一页
select * from newsTable where id < 14 and catid = 1 limit 1
上一页
select * from newsTable where id < 14 and catid = 1 limit 1
下一页
select * from newsTable where id > 14 and catid = 1 limit 1
你说的方法对,我把cateid也传过来了,但是问题是那样我查询的id不是正常顺序的id啊
比方说通过查询cateid=1得到的一条新闻id=13,我通过nextid=id+1来实现下页的链接,但是nextid=id+1就是id=14的新闻可能就不是cateid=1的新闻了啊?
select * from newsTable where id < 14 and catid = (select catid from newsTable where id = 14)下一页
select * from newsTable where id > 14 and catid = (select catid from newsTable where id = 14)
news.php
<?include("inc/conn.php");
$sql="select id,cateid,topic,body,coment from news where id='$messid' and cateid='$cateid' order by id";
$result=mysql_query($sql);
if($myrow=mysql_fetch_array($result))
{
$id=$myrow["id"];
$addid=$id+1;
$subid=$id-1;
$cateid=$myrow["cateid"];
$title=$myrow["topic"];
$body=$myrow["body"];
echo "<tr><td>$title</td></tr>";
echo "<tr><td>$body</td></tr>";
echo "<tr><td><A href='news.php?messid=$subid&&cateid=$cateid'>上一页</A></td>";
echo "<td><A href='news.php?messid=$addid&&cateid=$cateid'>下一页</A></td></tr>";
}
?>
随便写的,意思就是这样,大家看看为什么不行?
if(!empty($_GET['mode']))
{
if($_GET['mode'] == "pre")
$op = "<";
else
$op = ">";
$sql="select id,cateid,topic,body,coment from news where id $op '$curid'
and cateid='$cateid' order by id limit 1";
}$result=mysql_query($sql);
if($myrow=mysql_fetch_array($result))
{
$id=$myrow["id"];
$cateid=$myrow["cateid"];
$title=$myrow["topic"];
$body=$myrow["body"];
echo "<tr><td>$title</td></tr>";
echo "<tr><td>$body</td></tr>";
echo "<tr><td><A href='news.php?curid=$id$&cateid=$cateid&mode=pre'>上一页</A></td>";
echo "<td><A href='news.php?curid=$id&&cateid=$cateid&mode=next'>下一页</A></td></tr>";
}
?>