Reputation: 461
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 doing this the reverse way for a previous button too.
Upvotes: 4
Views: 3067
Reputation: 2404
$next=mysql_query("SELECT * FROM posts WHERE id<'{$id}' ORDER BY id LIMIT 1");
Upvotes: 2
Reputation: 61437
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
.
Upvotes: 5