I have a webpage from which a user can select an entry from a MySQL DB. After this entry is displayed, I would like to have one button that allows the user to select the next five DB entries and another button that allows the user to select the previous 5 entries.
How can I write the query for these two buttons?
I have a primary key column, _id
and a date column date
, but there are be gaps in both, i.e., selecting all data from the table results in:
+-----+------------+
| _id | date |
+-----+------------+
| 4 | 2020-11-26 |
| 5 | 2020-11-28 |
| 6 | 2020-11-29 |
| 7 | 2020-12-01 |
| 8 | 2020-12-08 |
| 10 | 2020-12-22 |
| 12 | 2020-12-25 |
+-----+------------+
For the first button (the next five entries) I have tried:
select * from Blog where post=1 and _id=5 order by date desc limit 5 offset 5;
which returns 0 records, and
select * from Blog where post=1 and _id>=5 order by date desc limit 5 offset 5;
which also returns 0 records.
I don't have a clue how to write the query for the second button, i.e. the previous five entries.
Any help would be appreciated.