due query tipo queste?

$avanti=mysql_query("select max (id) from fotoalbum where id='$chiave' limit 1 ");
$indietro=mysql_query("select min (id) from fotoalbum where id='$chiave' limit 1 ");