上一主题/下一主题的实现_[PHP教程] 第一种方法:定义通用函数
function shownext(){global thisid;query="select * from TABLE_NAME where id>thisid order by id limit 1";result=mysql_query(query);if(result=0){echo "已经是第一个主题了";}else{if(row=mysql_fetch_array(result))nextid=row["id"];echo "下一主题";}}function showpre(){global thisid;query="select * from TABLE_NAME where id>上一主题";}}
这里的 thisid 为当前主题的id
第二种方法:假设有一个主题链接为 (当前id为100)
detail.php?id=100&action=pre
或者
detail.php?id=100&action=next
然后在主题显示页面detail.php取记录时使用如下条件语句
switch(acttion) { case 'next': sql = "select * from table where id > id limit 0,1"; break; case 'prev': sql = "select * from table where id < id order by id desc limit 0,1"; break; default: sql = "select * from table where id = id"; }