I figure out how I can get the next id using this: $sql_next ="SELECT id FROM table WHERE id > $current_id ORDER BY id LIMIT 1"; if($result = $mysqli->query($query)) {while($row = $result->fetch_assoc()){ $next = $row['id']; echo '<a href="https://someurl.com/'.$next.'">Next</a>'; }} Code (markup): However, I am not sure how to get the previous id. I tried changing WHERE id < $current_id but it didn't do the trick. What should I use to get a previous record from the sql table?
+1 to qwikad.com unswer and also it's better to add additional check for the case if the query result would be empty (if there is no previous record). P.S. And by the way there is no need in "while" I suppose...considering "LIMIT 1" in the MySQL query.