首页 > 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 "<a href='xxx.php?id=<?=$nextid?>'>下一主题</a>";
    }
}
function showpre(){
    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))
        {
            $preid=row["id"];
            echo "<a href='xxx.php?id=<?=$preid>'>上一主题</a>";
        }
    }
}

这里的 $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";
}


本文链接:http://www.phprm.com/code/5cfb985c22d853f00bc4103a7c8e76b4.html

收藏随意^^请保留教程地址.

标签:none

发表留言