Le immagini non sono in una cartella, ma nel DB. So che non è la scelta migliore, ma ho voluto fare cosi. Comunque, per ricapitolare, ho due file:
1)contiene il codice base (che non sceglie casualmente fra più categorie), funziona ma mostra solo una immagine anziché due affiancate. Se però eseguo la query in phpMyAdmin la query funziona e restituisce due righe casuali. Il Codice:
Codice PHP:
<?
@include 'config.php';
$sql = "SELECT foto_id,foto_nome,foto_size,foto_type, foto, foto_cat,foto_naz FROM img WHERE foto_cat='Paesaggi' ORDER BY RAND() limit 2";
$result = @mysql_query($sql) or die(mysql_error ());
$row = @mysql_fetch_array($result);
$id_img = $row['foto_id'];
$type = $row['foto_type'];
$img = $row['foto'];
@header ("Content-type: ".$type);
echo $img;
?>
2)Il file con il codice più completo, ma che rimane bianco. Ti posto il codice aggiornato:
Codice PHP:
<?
include 'config.php';
$catList = array('Paesaggi', 'Ritratti');
$catList=array_rand($catList);
$catSel=$catList[0];
$sql = "SELECT foto_id,foto_nome,foto_size,foto_type, foto, foto_cat,foto_naz FROM img WHERE foto_cat = '".$catSel."' ORDER BY RAND() LIMIT 2";
$result = mysql_query($sql) or die(mysql_error ());
while($row = mysql_fetch_array($result)){
$id_img = $row['foto_id'];
$type = $row['foto_type'];
$img = $row['foto'];
if (!$id_img)
{
echo "Id sconosciuto";
}else{
header ("Content-type: ".$type);
echo $img;
echo '[img]'.$img.'[/img]';
}
}
?>