$querySEL = "select * from categorie where visibile ='si' order by data desc, id_cat desc";
//query di selezione categorie ------------------------------------
$resultSEL = mysqli_query($db, $querySEL);
while ($r = mysqli_fetch_object($resultSEL)) {
$id_cat1 = $r->id_cat;
$titolo_cat = $r->titolo_cat;
$data_cat = $r->data;
//$ordine_cat = $r->ordine;
$descrizione_cat = $r->descrizione_cat;
$visibile= $r->visibile;
$querySEL1 = "select * from foto where categoria = '$id_cat1' order by visibile desc limit 1";
?>
$resultSEL1 = mysqli_query($db,$querySEL1);
while ($r1= mysqli_fetch_object($resultSEL1)) {
$id_foto1 = $r1->id;
$titolof = $r1->titolo;
$nome_foto_name=$img_small = $r1->img_small;
$img_big = $r1->img_big;
//$ordine = $r1->ordine;
$visibile = $r1->visibile;
$oldf = $r1->descrizione_foto;?>
if ($oldf=='old') {?>
}else{?>
} } ?>
echo $titolo_cat;?>
} ?>