Php 快速找到我想要的页面之前和之后的页面
我是mysql的初学者,我想知道是否有一种更快的方法来执行以下操作: 我有一张这样的桌子:Php 快速找到我想要的页面之前和之后的页面,php,mysql,performance,Php,Mysql,Performance,我是mysql的初学者,我想知道是否有一种更快的方法来执行以下操作: 我有一张这样的桌子: ------------------------------ | Pages | Creation | ------------------------------ | bar | 2012-10-10 10:11:10| | blah | 0000-00-00 00:00:00| | foo | 2012-10-10 10:10:10| ------------------
------------------------------
| Pages | Creation |
------------------------------
| bar | 2012-10-10 10:11:10|
| blah | 0000-00-00 00:00:00|
| foo | 2012-10-10 10:10:10|
------------------------------
没有主键
我想知道特定页面之前的页面和之后的页面(按创建日期排序)
目前我有:
Sql:按创建顺序从表中选择*
Php:
上一页:
SELECT table.Pages
FROM table, (SELECT Creation FROM table WHERE Pages = "'.$page.'") AS t2
WHERE table.Creation < t2.Creation
ORDER BY table.Creation DESC
LIMIT 1
您应该使用主键,这样您就可以完全识别当前页面。
SELECT table.Pages
FROM table, (SELECT Creation FROM table WHERE Pages = "'.$page.'") AS t2
WHERE table.Creation < t2.Creation
ORDER BY table.Creation DESC
LIMIT 1
SELECT table.Pages
FROM table, (SELECT Creation FROM table WHERE Pages = "'.$page.'") AS t2
WHERE table.Creation > t2.Creation
ORDER BY table.Creation ASC
LIMIT 1