开发者

MySQL query for ID < variable

开发者 https://www.devze.com 2023-02-16 16:41 出处:网络
Hey, so what I am looking to accomplish is a MySQL query which grabs just the FIRST row whos ID is less than my current one. So basically a next button. Here is what I would like to modify:

Hey, so what I am looking to accomplish is a MySQL query which grabs just the FIRST row whos ID is less than my current one. So basically a next button. Here is what I would like to modify:

$next = mysql_query("select * from posts where id<'$id'");

So how would I change this so it only selects the first value which is less than my ID value (which is the id of my current page)

Thanks! I will be doin开发者_JAVA技巧g this the reverse way for a previous button too.


select * from posts where id<'$id' order by id desc limit 1

This will get you the first id smaller than the provided parameter $id.


$next=mysql_query("SELECT * FROM posts WHERE id<'{$id}' ORDER BY id LIMIT 1");
0

精彩评论

暂无评论...
验证码 换一张
取 消