My page looks like:
| << back button | IMAGE | forward button >> |
Every row have an unique ID number, and with that ID I’m getting result from my data base.
The << back button is a hyperlink, and it should contain the previous row ID. The forward button >> should contain the next row ID.
The ID column has INTEGER values with AUTO_INCREMENT.
How I should wrote my query? Can I use negative values? Something like:
SELECT * FROM `db` ORDER BY `ID` DESC LIMIT -1, 1
Does it work?
You can’t use negative values, but you can use your current
idin theWHEREclause to find values less than it, order byID DESCand limit to 3. Theauto_incrementid column is sorted in descending order, so the first 3 values that are less than your currently selected id will be targeted.Likewise to get the next three, use
>and sort in ascending order.