作业帮 > PHP > 教育资讯

PHP教程:PHP如何实现文章的上一篇下一篇

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/11 13:53:40 PHP
PHP教程:PHP如何实现文章的上一篇下一篇
PHP教程:PHP如何实现文章的上一篇下一篇PHP
【51Test.NET-PHP教程:PHP如何实现文章的上一篇下一篇】:

在新闻资讯类、博客文章类的网站,必须要有的一个功能就是,浏览一篇文章的时候,必须要给出上一篇和下一篇文章的链接。这个是怎么实现的呢?

下面给出mysql中如何取得当前文章的上一篇和下一篇
就以wordpress的文章表结构来做例子吧
wp_posts的表结构如下:

01 CREATE TABLE `wp_posts` (

02 `ID` bigint(20) unsigned NOT NULL auto_increment,

03 `post_author` bigint(20) unsigned NOT NULL default '0',

04 `post_date` datetime NOT NULL default '0000-00-00 00:00:00',

05 `post_date_gmt` datetime NOT NULL default '0000-00-00 00:00:00',

06 `post_content` longtext NOT NULL,

07 `post_title` text NOT NULL,

08 `post_excerpt` text NOT NULL,

09 `post_status` varchar(20) NOT NULL default 'publish',

10 `comment_status` varchar(20) NOT NULL default 'open',

11 `ping_status` varchar(20) NOT NULL default 'open',

12 `post_password` varchar(20) NOT NULL default '',

13 `post_name` varchar(200) NOT NULL default '',

14 `to_ping` text NOT NULL,

15 `pinged` text NOT NULL,

16 `post_modified` datetime NOT NULL default '0000-00-00 00:00:00',

17 `post_modified_gmt` datetime NOT NULL default '0000-00-00 00:00:00',

18 `post_content_filtered` text NOT NULL,

19 `post_parent` bigint(20) unsigned NOT NULL default '0',

20 `guid` varchar(255) NOT NULL default '',

21 `menu_order` int(11) NOT NULL default '0',

22 `post_type` varchar(20) NOT NULL default 'post',

23 `post_mime_type` varchar(100) NOT NULL default '',

24 `comment_count` bigint(20) NOT NULL default '0',

25 PRIMARY KEY (`ID`),

26 KEY `post_name` (`post_name`),

27 KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),

28 KEY `post_parent` (`post_parent`),

29 KEY `post_author` (`post_author`)

30 ) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
假如当前文章的ID为6,那么取得上一篇文章的信息就用下面的SQL语句

view sourceprint?
1 select * from wp_posts where ID < 6 order by comment_ID DESC limit 1
取得下一篇文章的信息就用下面的SQL语句

view sourceprint?
1 select * from wp_posts where ID > 6 order by comment_ID ASC limit 1

PHP