Home  >  Article  >  Backend Development  >  当前文章的上一篇、下一篇文章如何设计?

当前文章的上一篇、下一篇文章如何设计?

WBOY
WBOYOriginal
2016-06-06 20:43:251569browse

在查看文章详情页面,

最底下有个上一篇、下一篇文章的链接,

问下大家都是怎么实现这个功能的?

一般情况下,文章详情都是通过传递id过去,

在数据库中读取此id的记录,

那上一篇和下一篇总不能用id-1或者id+1这种方法实现吧,

有时候文章的id不是连续了,出于某些情况会删掉某条记录,

这样就导致了id不连续,

所以id-1或者id+1的方法是错误的,

大家有没有其他方法?

回复内容:

在查看文章详情页面,

最底下有个上一篇、下一篇文章的链接,

问下大家都是怎么实现这个功能的?

一般情况下,文章详情都是通过传递id过去,

在数据库中读取此id的记录,

那上一篇和下一篇总不能用id-1或者id+1这种方法实现吧,

有时候文章的id不是连续了,出于某些情况会删掉某条记录,

这样就导致了id不连续,

所以id-1或者id+1的方法是错误的,

大家有没有其他方法?

$sql = '(select id,title from articles where id  :id order by id asc limit 1)';

mysql: select id from table where id>10 order by id desc limit 1

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