$result = mysql_db_query ( "$database", "SELECT * FROM gruppi_foto ORDER BY POS");
while ($valori = mysql_fetch_array ($result)){
$idgruppo=$valori["ID"];
$nomegruppo=$valori["TESTOIT"];
?>
$result2 = mysql_db_query ( "$database", "SELECT * FROM foto WHERE IDGR='$idgruppo' ORDER BY POS");
while ($valori2 = mysql_fetch_array ($result2)){
$idfoto=$valori2["ID"];
$didafoto=$valori2["DIDAIT"];
?>
}?>
}?>