Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Estou tentando selecionar uma foto de cada album com a função rand.
Porem soh retorna um resultado mesmo tendo mais.
<?php
$sql= "Select Album from fotos group by Album";
$result=mysql_query($sql)or die(mysql_error());
$num=mysql_num_rows($result);
while($linhaalbum=mysql_fetch_array($result)){
$album=$linhaalbum["Album"];
$sql= "Select Id_Foto from fotos where Album='$album'";
$result=mysql_query($sql)or die(mysql_error());
$num=mysql_num_rows($result);
$n=$num-1;
$idf=array();
$x=0;
while($linhafoto=mysql_fetch_array($result)){
$idf[$x]=$linhafoto["Id_Foto"];
$x++;
}
$idfoto=$idf[rand(0,$n)];
$sqlfoto= "Select Album, Nome, Foto from fotos where Id_Foto='$idfoto'";
$resultfoto=mysql_query($sqlfoto)or die(mysql_error());
$i=mysql_num_rows($resultfoto);
while ($linhafoto=mysql_fetch_array($resultfoto)){
$nomefoto= $linhafoto["Nome"];
$albumfoto= $linhafoto["Album"];
$fotoalbum= $linhafoto["Foto"];
$a=$albumfoto."/".$fotoalbum;
?>
<img class=tronclick onClick="window.location.href='exibirfoto.php?id=<?php echo $idfoto?>&al=<?php echo $albumfoto; ?>'" src="<?php echo "img/$a"; ?>" width=100 height=100 alt=<?php echo $nomefoto; ?>><BR>
<?php
echo "$album";
}
}
?>Carregando comentários...