M
M
Miku Hatsune2015-11-17 13:32:10
PHP
Miku Hatsune, 2015-11-17 13:32:10

SQL. How to "find out the next" line?

Look, there is a "files" table. For example, it has 2 fields: id (auto-increment) and name.
For example, the user is looking at a file with id - 2. I need to implement the "Next File" and "Previous File" buttons.
But I don't know how to do this, since over time id can be scattered (for example, the file was deleted).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2015-11-17
@Hatsune-Miku

Next - SELECT * FROM FILES WHERE ID > '2' ORDER BY ID LIMIT 1
previous SELECT * FROM FILES WHERE ID < '2' ORDER BY ID LIMIT 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question