This will get the previous and next id in 2 different queries. Of course you need to make sure that no sql injection occurs, and validate that something is returned (that there are previous and returned id).
// Previous id
SELECT something
FROM somewhere
WHERE id < $id
ORDER BY id DESC
LIMIT 0, 1
// Next id
SELECT something
FROM somewhere
WHERE id > $id
ORDER BY id ASC
LIMIT 0, 1