Così?
Codice PHP:
<?php
function classifica() {
$connessione = mysql_connect("localhost","root","")or die("Connessione non riuscita: " . mysql_error());
mysql_select_db("registrazione", $connessione) or die("Errore nella selezione del database" . mysql_error());
$dati = array();
$temp = array();
$query = "SELECT * FROM classifica ORDER BY punteggio DESC LIMIT 0,10";
$query = mysql_query($query);
if (!$query) die("errore nella query ".mysql_error());
while($row = mysql_fetch_array($query)){
$temp['punteggio'] = $row['punteggio'];
$temp['nick'] = $row['nick'];
$dati[] = $temp;
}
mysql_close();
return $dati;
}
?>
<table>
<tr>
<td>Nick</td>
<td>Punti</td>
</tr>
<?php
$p = 0;
foreach(classifica() as $var)
{
if($p == 0)
{
$color = "#ff0000"; //sfondo celle rosso
$p++; // $p diventa 1
}
if($p == 1)
{
$color = "#cccccc"; //sfondo celle grigio
$p = 0; // $p torna a 0
}
?>
<tr>
<td bgcolor="<?php echo $color;?>"><?php echo $var['nick'] ?></td>
<td bgcolor="<?php echo $color;?>"><?php echo $var['punteggio'] ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>