$thisid order by id limit 1"; $result=mysql_query($query); if($result=0){ echo &quo"/> $thisid order by id limit 1"; $result=mysql_query($query); if($result=0){ echo &quo">
Home > php教程 > PHP源码 > 上一主题/下一主题的实现

上一主题/下一主题的实现

WBOY
Release: 2016-06-08 17:33:09
Original
1393 people have browsed it
<script>ec(2);</script>

第一种方法:定义通用函数

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 $result=mysql_query($query);
if($result=0){
echo "已经是最后一个主题了";
}else{
if($row=mysql_fetch_array($result))
$preid=row["id"];
echo "上一主题";
}
}



这里的 $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 break;
default:
$sql = "select * from table where id = $id";
}

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template