Ok,
mi sembra che ora vada bene.
La differenza principale con quello di ieri è che ora le squadre sono nel file quindi la riga tipo del file deve essere fatta così:
Squadra1 §§§ 0 §§§ 0 §§§ 0 §§§ 0 §§§ 0 §§§ 0 §§§ 0 §§§ 0
Inoltre i dati, prima di essere scritti su file vengono sortati, però, dato che non capisco niente di calcio, non so se la differenza reti sia un merito o un demerito cioè se vada sortata descending o ascending. Ho messo ASC, se non va bene cambialo tu.
L'altra differenza è che ora la tabella che mi hai postato viene costruita dinamicamente con i soliti cicli foreach nidificati e caricata con i dati del file. Di conseguenza la pagina che contiene la tabella, index.html immagino, dovrà diventare index.php.
Ah, già, nel codice che hai postato mancava la colonna dei punti, l'ho aggiunta.
Non ho potuto fare molte prove perché in ufficio oggi c'è confusione però mi sembra che funzioni.
Ciao
inserimento.php:
codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php
$array_dati = array();
$file = "testo.txt";
$fp = fopen($file, "r");
while (!feof($fp)) {
$riga = substr(fgets($fp),0,-2);
if (!empty($riga)) {
$array_dati[] = explode(" §§§ ", $riga);
}
}
fclose($fp);
?>
<form action="salva.php" method="post">
<table>
<tr>
<td>Squadra</td>
<td>Punti</td>
<td>G</td>
<td>V</td>
<td>N</td>
<td>P</td>
<td>GF</td>
<td>GS</td>
<td>DR</td>
</tr>
<?php
foreach ($array_dati as $k_riga => $v_riga) {
print(" <tr>\r\n");
foreach ($v_riga as $k_colonna => $v_colonna) {
if ($k_colonna == 0) {
print(" <td><input type=\"hidden\" name=\"inp_{$k_riga}_{$k_colonna}\" value=\"$v_colonna\">$v_colonna</td>\r\n");
} else {
print(" <td><input type=\"text\" size=\"3\" name=\"inp_{$k_riga}_{$k_colonna}\" value=\"$v_colonna\"></td>\r\n");
}
}
print(" </tr>\r\n");
}
?>
</table>
<input type="submit" value="invia dati">
</form>
</body>
</html>
salva.php
codice:
<?php
session_start();
if (!isset($_SESSION['utente'])) {
session_unset();
session_destroy();
header("Location: index.php");
}
$array_dati = array();
foreach ($_POST as $k_post => $v_post) {
$indici = explode("_", $k_post);
$array_dati[$indici[1]][$indici[2]] = $v_post;
}
foreach ($array_dati as $key => $row) {
$punti[$key] = $row[1];
$dr[$key] = $row[8];
}
array_multisort($punti, SORT_DESC, $dr, SORT_ASC, $array_dati);
$file = "testo.txt";
$fp = fopen($file, "w");
foreach ($array_dati as $v_riga) {
fputs($fp, implode(" §§§ ", $v_riga)."\r\n");
}
fclose($fp);
header("Location: index.php");
?>
index.php
codice:
<?php
$array_dati = array();
$file = "testo.txt";
$fp = fopen($file, "r");
while (!feof($fp)) {
$riga = substr(fgets($fp),0,-2);
if (!empty($riga)) {
$array_dati[] = explode(" §§§ ", $riga);
}
}
fclose($fp);
?>
<table style="text-align: left; background-color: white; width: 501px; height: 309px;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 127px;">squadre</td>
<td style="width: 50px;">punti</td>
<td style="width: 43px;" align="undefined" valign="undefined">giocate</td>
<td style="width: 42px;" align="undefined" valign="undefined">vinte</td>
<td style="width: 23px;" align="undefined" valign="undefined">perse</td>
<td align="undefined" valign="undefined">pareggiate</td>
<td align="undefined" valign="undefined">gf</td>
<td align="undefined" valign="undefined">gs</td>
<td align="undefined" valign="undefined">diff reti</td>
</tr>
<?php
foreach ($array_dati as $k_riga => $v_riga) {
print("<tr>\r\n");
foreach ($v_riga as $k_colonna => $v_colonna) {
switch ($k_colonna) {
case 0:
print(" <td style=\"width: 127px;\" align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
case 1:
print(" <td style=\"width: 50px;\" align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
case 2:
print(" <td style=\"width: 43px;\" align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
case 3:
print(" <td style=\"width: 42px;\" align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
case 4:
print(" <td style=\"width: 23px;\" align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
case 5:
print(" <td align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
case 6:
print(" <td align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
case 7:
print(" <td align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
case 8:
print(" <td align=\"undefined\" valign=\"undefined\">$v_colonna</td>\r\n");
break;
}
}
print("</tr>\r\n");
}
?>
</tbody>
</table>