I have a table that looks something like this:
___________
|ID | Message|
------------------
1 a
2 b
3 c
4 d
Say I am currently accessing the 4th row (ID=4, Message=d), so my
currentID=4, currentMessage='d'
I want to access the NEXT row where ID < currentID, which is the row with
ID=3, Message=c
my query statement to access this next row looks like this:
$query = "select * from messagesTable where ID < currentID limit 1";
the problem with this query is that mysql returns the first row, which is:
currentID=1, Message=a
How do I structure the $query statement to access the next row where ID=3, Message=c?
(please excuse the appearance of the table...thats actually 2 columns squashed together..I couldlnt space them out)
how to get immediate next item in database?
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Code: Select all
select * from `messagesTable` where `ID` < currentID ORDER BY `ID` DESC limit 1