0

我是 mysql 的初学者,我想知道是否有更快的方法来执行以下操作:

我有一张这样的桌子:

------------------------------
| Pages |      Creation      |
------------------------------
| bar   | 2012-10-10 10:11:10|
| blah  | 0000-00-00 00:00:00|
| foo   | 2012-10-10 10:10:10|
------------------------------

没有主键。

我想知道特定页面之前的页面和之后的页面(按创建日期排序)。

目前我做:

数据:SELECT * FROM table ORDER BY creation

php:

foreach($r as $c=>$t)
{
    if($t['pages']==$thepageiwant)
    {
        $before=$c-1;
        $after=$c+1;
        break;
    }
}
4

1 回答 1

2

上一页:

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
于 2012-12-02T18:08:57.267 回答