MySQL query for ID <variable

Hey, so what I want to execute is a MySQL query that only captures the FIRST row whos ID less than my current. So basically the next button. Here is what I would like to change:

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

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

Thanks! I will also do this the other way around for the previous button.

+4
source share
2 answers
 select * from posts where id<'$id' order by id desc limit 1 

This will give you the first identifier less than the given $id parameter.

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

Source: https://habr.com/ru/post/1343704/


All Articles