我是 mysql 的初学者,我想知道是否有更快的方法来执行以下操作:
我有一个这样的表:
------------------------------
| Pages | Creation |
------------------------------
| bar | 2012-10-10 10:11:10|
| blah | 0000-00-00 00:00:00|
| foo | 2012-10-10 10:10:10|
------------------------------
没有主键。
我想知道特定页面之前的页面和之后的页面(按创建日期排序)。
目前我做的是:
Sql:SELECT * FROM 表 ORDER BY 创建
PHP:
foreach($r as $c=>$t)
{
if($t['pages']==$thepageiwant)
{
$before=$c-1;
$after=$c+1;
break;
}
}
最佳答案
上一页:
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
关于php - 快速找到我想要的页面之前和之后的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13671988/