Questo serve per creare la tabella mysql:
Questa è la pagina di amministrazione:codice:CREATE TABLE classifica ( id int(11) NOT NULL auto_increment, nome varchar(100) NOT NULL, nick varchar(50) NOT NULL, citta varchar(100) NOT NULL, punteggio int(11) NOT NULL, PRIMARY KEY (id) )
Questa è la pagina con la classifica:Codice PHP:<?php
if (isset($_POST['punteggio'])) {
foreach ($_POST['punteggio'] as $id => $punteggio) {
$res = mysql_query("UPDATE classifica SET punteggio = $punteggio WHERE id = $id") or die (mysql_error());
}
}
?>
<form action="prova.php" method="post">
<table>
<tr>
<th>Nome</th>
<th>Nick</th>
<th>Città</th>
<th>Punteggio</th>
</tr>
<?php
$res = mysql_query("SELECT * FROM classifica") or die (mysql_error());
while ($elenco = mysql_fetch_assoc($res)) {
?>
<tr>
<td><?php echo $elenco['nome']; ?></td>
<td><?php echo $elenco['nick']; ?></td>
<td><?php echo $elenco['citta']; ?></td>
<td><input type="text" name="punteggio[<?php echo $elenco['id']; ?>]" value="<?php echo $elenco['punteggio']; ?>" /></td>
</tr>
<?php } ?>
</table>
<button type="submit">Salva</button>
</form>
CiaoCodice PHP:<table>
<tr>
<th>Posizione</th>
<th>Nome</th>
<th>Nick</th>
<th>Città</th>
<th>Punteggio</th>
</tr>
<?php
$res = mysql_query("SELECT * FROM classifica ORDER BY punteggio DESC") or die (mysql_error());
$x = 0;
while ($elenco = mysql_fetch_assoc($res)) { $x++;
?>
<tr>
<td><?php echo $x; ?></td>
<td><?php echo $elenco['nome']; ?></td>
<td><?php echo $elenco['nick']; ?></td>
<td><?php echo $elenco['citta']; ?></td>
<td><?php echo $elenco['punteggio']; ?></td>
</tr>
<?php } ?>
</table>![]()

Rispondi quotando