$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">
search
Homephp教程PHP源码上一主题/下一主题的实现

<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";
}

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version