Hi!
perhaps it would be helpfull, if the id for the prev und next row would be written in the session.
for exemple:
$nextlink.= "editid##@index##=".htmlspecialchars(rawurlencode($next[##@index##]));
$_SESSION["nextlink"]=$nextlink;
and
$prevlink.= "editid##@index##=".htmlspecialchars(rawurlencode($prev[##@index##]));
$_SESSION["prevlink"]=$prevlink;