Codice PHP:
$sql "SELECT MAX(id_info) as maxid FROM Tabella WHERE id_annuncio=".$id;
$result mysql_query($sql);
$nuovoId=1;
if(
$row mysql_fetch_array($result))
{
    
$nuovoId=$row['maxid']+1;
}
echo 
"NUOVO ID=".$nuovoId