如何使用php构建下一个和上一个链接? [英] How to build next and previous links with php?
问题描述
我使用此代码获取有关某个ID的信息
I use this code to get the informations about a certain id
$sql = dbquery("SELECT * FROM `videos` WHERE `id` = ".$local_id." ");
while($row = mysql_fetch_array($sql)){
$video_id = $row["id"];
$video_title = $row["title"];
}
让我们说一个页面的链接是example.com/video.php ?id = 34
Let's say the link of a page would be example.com/video.php?id=34
如何根据当前ID获取下一个和之前的$ video_id和$ video_title?
How can i get the next and previous $video_id and $video_title depending on the current id?
问题是我不能将当前id的值增加或减少1,因为同时可以删除35或33 ......
A problem is that i can't increase or decrease the value of the current id by 1 because the 35 or 33 may be deleted in the meanwhile...
我怎样才能做到这一点?
How can i achieve this?
//编辑
我有一个很大的问题:上一个链接将我发送到正确的链接,但下一个链接总是将我发送到数据库中添加的最后一个视频。
I have a very big problem: the previous link sends me to the right link but the next link always sends me to the last video added in the database.
如果我转到数据库中添加的最后一个或第一个视频,我会收到错误,因为不再添加下一个和上一个视频。
If i go to the last or first videos added in the database i get an error because there are no more next and previous videos added.
推荐答案
也许还有两个查询可以运行...
Perhaps two more queries would work ...
select id,title from videos where id < $local_id order by id desc limit 1
select id,title from videos where id > $local_id order by id asc limit 1
这篇关于如何使用php构建下一个和上一个链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!