select id from tabella where id > $id order by id asc limit 1

select id from tabella where id < $id order by id desc limit 1