Ciao a tutti, ho bisogno di visualizzare un immagine in base al risultato del database, mi spiego meglio, nel database ho una tabella chiamata "hotel" dove all'interno ho messo una riga chiamata "stato" con i campi " aperto e chiuso" dove in base al risultato visualizzo e meno l'hotel adesso vorrei abbinare allo stato "aperto" una foto con il puntino verde ed allo stato "chiuso" una foto con il punti rosso pero' questa volta non so proprio da dove iniziare vi posto il codice dove devo mettere la foto:
in pratica sul questo punto devo inserire l'immagine:
Grazie in anticipo ragazzi
PHP:
<?
require ('../processi/config.php');
// funzione per generare ratings
function generate_ratings($rating) {
$stelle = '';
for ($i = 0; $i < $rating; $i++) {
$stelle .= '<img src="http://forum.mrwebmaster.it/img/star.png" width="16" height="16" />';
}
return $stelle;
}
$query = 'SELECT * FROM hotel ORDER by nome';
$result=mysql_query($query);
if (mysql_num_rows($result) == 0) {
echo '<table align="center" class="clear" cellpadding="4" cellspacing="0" border="0" width="100%">';
echo '<td align=center class="require">NON CI SONO HOTEL INSERITI!</td>';
echo '</table>';
exit;
} else
?>
<!---------INIZIO TESTATA TABELLA------------>
<table id="my-table" align="center" class="dataTables_filter" cellpadding="0" cellspacing="0" width="80%">
<thead>
<tr>
<th style="width: 21px;" colspan="1" rowspan="1" class="center sorting_disabled" width="1%"><input name="checkAll" id="checkAll" class="checkAll_btn" type="checkbox" /></th>
<th style="width: 43px;" colspan="1" rowspan="1" class="sorting" width="4%">Id</th>
<th style="width: 71px;" colspan="1" rowspan="1" class="sorting" width="10%">Categoria </th>
<th style="width: 99px;" colspan="1" rowspan="1" class="sorting_asc" width="13%">Foto </th>
<th style="width: 178px;" colspan="1" rowspan="1" class="sorting" width="23%">Nome Hotel </th>
<th style="width: 178px;" colspan="1" rowspan="1" class="sorting" width="23%">Stelle </th>
<th style="width: 57px;" colspan="1" rowspan="1" class="sorting" width="8%">Stato</th>
<th style="width: 152px;" colspan="1" rowspan="1" class="sorting" width="20%">Azione</th>
</tr>
</thead>
<?
while ($row=mysql_fetch_array($result)) {
//genero il ciclo while per le stelle
$rating = generate_ratings($row['stelle']);
echo'<tbody>';
echo"<tr class='odd' onmouseover='this.bgColor='#FCF5DD';' onmouseout='this.bgColor='#FFF';' bgcolor='#FFF'>";
echo' <td class="center checkbox"><input name="checkbtn" id="checkbtn" value="14" class="check_btn" type="checkbox" /></td>';
echo'<td class="center" align="left">' . $row['idhotel'] . '</td>';
echo'<td> ' . $row['categoria'] . ' </td>';
// recupero i dati dal DB
$query = 'SELECT * FROM hotel h JOIN images i ON h.idhotel=i.idhotel WHERE i.idhotel = ' . $row['idhotel'] . ' ORDER BY id ASC LIMIT 1';
$res = mysql_query($query) or die (mysql_error($connessione));
$path_img = "../foto hotel/";
// numero delle immagini presenti nel DB
$n_img = mysql_num_rows($res);
// verifico che il DB ospiti almeno un'immagine
if($n_img >= 1 ){
// stabilisco il numero di riche e colonne della nostra tabella per l'impagninazione
// ciclo tutti i record recuperati attraverso la nostra query
while ($f=mysql_fetch_array($res)){
$id = $f['id'];
$descrizione = stripslashes($f['descrizione']);
$nome = stripslashes($f['nome']);
$idhotel = stripslashes($f['idhotel']);
// stampo la cella contenente l'immagine
echo '<td span style="z-index: 0;" class="thumb"><img style="overflow: hidden; margin-top: -4px; margin-left: 0px; top: 0px; left: 0px; width: 30px; height: 20px; padding: 5px;" src="http://forum.mrwebmaster.it/foto hotel/' . $nome . '.jpg" width="49" height="30" class="dimensione"></span></td>';
// quando il numero di righe equivale al valore impostato nella variabile $righe
// procedo a chiudere la linea e ad azzerare il valore di $righe
}
}else{
// stampo un messaggio se il DB è vuoto
echo '<td><img src="http://forum.mrwebmaster.it/icone/not.gif" WIDTH="18" HEIGHT="16" border="0" /></td>';
}
echo'<td class="nome_hotel"> ' . $row['nome'] . '</td>';
echo'<td>' . $rating . '</td>';
echo'<td>' . $row['stato'] . '</td>';
echo'<td class="tools-list"><ul>';
echo"<li> <a href='../pagine/edit-hotel.php?id=" . $row['idhotel'] . "' class='tooltip'><img src='../icone/edit.png' border='0' /><span>Modifica</span></a> </li>";
echo"<li> <a href='../pagine/vedi_hotel.php?id= ". $row['idhotel'] . " ' class='tooltip'><img src='../icone/view.gif' WIDTH='18' HEIGHT='16' border='0' /><span>Vedi Dettagli</span></a> </li>";
echo" <li> <a href='../java processi/conferma_cancella_tutto.php?id= " . $row['idhotel'] . " ' class='tooltip'><img src='../icone/delete.gif' WIDTH='16' HEIGHT='19' border='0' /><span>Elimina</span></a> </li>";
echo'</ul></td>';
echo'</tr>';
echo'</tbody>';
}
?>
PHP:
echo'<td>' . $row['stato'] . '</td>';