Here is an easy way to select the previous and next entry based on a given ID in MySQL, good for paginations in PHP.
To get the previous entry, query is “SELECT * FROM table_name WHERE id $current_id ORDER BY id ASC LIMIT 1″
You might think it’s easier to use (id – 1) or (id + 1) but it might return errors when id’s are deleted and the count is broken.
Advertisement