Settings | Sign in | Sign up

There is currently 1 post.

MYSQL 取上一条记录,与下一条记录

Floor 1 221.236.48.* 12/7/10 20:01

$id 为当前 ID,仅供参考:

SELECT id FROM table WHERE id>$id ORDER BY id ASC LIMIT 1

SELECT id FROM table WHERE id<$id ORDER by id DESC LIMIT 1

♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂♂

mysql取上一条记录,与下一条记录,哈,会者不难,难者不会,只要知道方法,这个还是比较简单的

下面看如何取上一条记录,

$id=$_GET[id];//当前ID记录

$sql="select * from table where id<'$id' order by id desc limit 1";

这条SQL语句就是取上一条记录,当然,你可以通过limit 1,修改这里得到多几条记录.

然后取下一条也比较简单了..

$sql="select * from table where id>'$id'  limit 1";

这句是取下一条的SQL语句哦..

取上一条记录,下一条记录后,还得处理一下是当没有记录的时候做个提示..这个比较容易就不写了!

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
©2010-2025 Purasbar Ver3.0 [Mobile] [Desktop]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported license.