allora modifica fatta al codice:
Codice PHP:
echo "<form action=\"salva_lista.php\" method=\"post\">";
echo "
<table width=\"100%\">";
echo "<tr><th id=\"year-container\">Nome</th><th id=\"year-container\">Cognome</th><th id=\"year-container\">Telefono</th><th id=\"year-container\">Note Telefonata</th></tr>";
// Show the events for the day
$sql = mysql_query("SELECT * FROM ".$_POST['listname']."", $db);
if (mysql_num_rows($sql) > 0) {
$id=1;
while ($e = mysql_fetch_array($sql)) {
echo "<tr><td class=\"day-currentMonth-weekday\">$e[nome]</td><td class=\"day-currentMonth-weekday\">$e[cognome]</td><td class=\"day-currentMonth-weekday\">$e[telefono]</td><td class=\"day-currentMonth-weekday\" width=\"80\"><input name=\"note[$id]\" type=\"text\" value=\"$e[note]\" size=\"80\"/></td></tr>";
$id++;
}
} else {
echo "
Nessun Record Trovato</p>\n";
}
// Close the database
mysql_close($db);
echo"<input type=\"submit\" value=\"Salva la lista\" />";
echo "</table>";
echo "</form>";
ho modificato la classe creando un form e imposto il nome di ogni input con note[$id] che prende valori crescenti; pertanto i valori sono note[1] note[2] note[3] etc
cliccando poi su salva la lista si passa ad un ulteriore file:
Codice PHP:
$db = mysql_connect($db_host, $db_user, $db_password)
or die ("Impossibile connettersi al server!");
mysql_select_db($db_database, $db)
or die ("Impossibile connettersi al database!");
foreach($_POST['note'] as $id => $text){
if(!empty($text)){
mysql_query('UPDATE `test` SET `note` = '.$text.' WHERE `id` = '.$id.';', $db)
or die ("Attenzione, impossibile inserire ii record(". mysql_error().")");
}
}
mysql_close($db);
qui però mi da problemi non so come leggere note[1] note[2] note[3], così mi da un errore:
Attenzione, impossibile inserire ii record(Unknown column 'test' in 'field list')
inoltre il pulsante "salva la lista" mi compare prima della tabella dei valori come mai?
un aiutino please.