Ho seguito questo post di Piero http://forum.html.it/forum/showthrea...hreadid=810119 . E' molto ben fatto, ma alcuni passaggi per me sono un po' complicati.
Devo fare update multipli, cioè devo visualizzare i record di un database in base alla classe, alla sezione e alla fascia scelti, quindi aggiornare i record modificati. La visualizzazione appare in una tabella.

Questo è il codice (molto lungo, ma lo posto tutto perchè già mi trovo in difficoltà). E' presente nella stessa pagina il form e la destinazione (dove viene fatto l'update).

Codice PHP:
            <?php
                
include("../config.php");

            
$z=0;
            echo 
"<form action='$_SERVER[PHP_SELF]' method='post'>            
            <table width='80%' cellpadding='3' cellspacing='1' border='0' class='sfondomenu' align='center'>
                <tr>
                <th>Inserimento dei voti per classe</th>
                </tr>
                    <tr class='row1'>
                        <td align='center' nowrap>
                        <table class='sottomenu' cellpadding='5' cellspacing='0' border='0' width='50%' align='center'>

                        <tr>
                        <td class='tabSup'>Cognome</td>
                            <td class='tabSup'>Nome</td>
                            <td class='tabSup'>Data voto</td>
                            <td class='tabSup'>Voto</td>
                            <td class='tabSup'>Tipologia Voto</td>
                        </tr>"
;

                        
$classe=$_POST['classe'];
                        
$sezione=$_POST['sezione'];
                        
$fascia=$_POST['fascia'];
                        
$materia=$_POST['materia'];

                        
$q "SELECT * FROM Valutazioni WHERE Valutazione_classe='$classe' AND Valutazione_sezione='$sezione' AND Valutazione_fascia='$fascia' AND Valutazione_materia_descrizione_estesa='$materia'";
                            
$query mysql_query($q) or die(mysql_error());
                        
$num mysql_num_rows($query);
                        
$z=0;
                        for(
$i=0;$i<$num;$i++){;
                            
$cognome=mysql_result($query,$i"Valutazione_alunno_cognome");
                            
$nome=mysql_result($query,$i"Valutazione_alunno_nome");
                            
$voto=mysql_result($query,$i"Valutazione_voto");
                            
$data=mysql_result($query,$i"Valutazione_data_voto");
                            
$tipo=mysql_result($query,$i"Valutazione_tipologia");
                            if(
$i%2==0){
                                echo 
"<tr>";
                                    echo 
"<input type='hidden' name=id[$z] value='$i'>";
                                    echo 
"<td class="."tabDispari".">$cognome</td>";
                                    echo 
"<td class="."tabDispari".">$nome</td>";
                                    echo 
"<td class="."tabDispari"."><input type='text' name=newdata[$z] value='$data'></td></td>";
                                    echo 
"<td class="."tabDispari"."><input type='text' name=newvoto[$z] value='$voto'></td></td>";
                                    echo 
"<td class="."tabDispari"."><input type='text' name=newtipo[$z] value='$tipo'></td></td>";

                                }
                            else{
                                echo 
"<tr>";
                                    echo 
"<input type='hidden' name=id[$z] value='$i'>";
                                    echo 
"<td class="."tabPari".">$cognome</td>";
                                    echo 
"<td class="."tabPari".">$nome</td>";
                                    echo 
"<td class="."tabPari"."><input type='text' name=newdata[$z] value='$data'></td></td>";
                                    echo 
"<td class="."tabPari"."><input type='text' name=newvoto[$z] value='$voto'></td></td>";
                                    echo 
"<td class="."tabPari"."><input type='text' name=newtipo[$z] value='$tipo'></td></td>";
                                echo 
"</tr>";
                                }
                            
$z=$z+1;
                        }

                echo 
"<tr>
                                <td align='center' nowrap>
                        <input type='submit' class='button' value='Modifica selezionato'>
                                </td>
                </tr>

                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td class='cat'></td>
                    </tr>
            </form> 
            </table> "
;


//Destinazione

if(!empty($_POST)){
    foreach(
$_POST as $key => $value ) {
              
$campo[] = $key;
    }
    foreach(
$_POST[$campo[0]] as $key0 => $val0 ) {
              
$id[] = $val0;   }

    foreach(
$_POST[$campo[1]] as $key1 => $val1 ) {
              
$newdata[] = $val1;   }


    foreach(
$_POST[$campo[2]] as $key2 => $val2 ) {
              
$newvoto[] = $val2;   }


    foreach(
$_POST[$campo[3]] as $key3 => $val3 ) {
              
$newtipo[] = $val3;   }

    for(
$i 0$i count($id); $i++) {
        echo 
$query "update Valutazioni set Valutazione_data='$newdata[$z]', Valutazione_tipologia='$newtipo[$z]', Valutazione_voto= '$newvoto[$z]' where id = '$id[$z]'
"
;
    }

}

        
$query mysql_query($q) or die(mysql_error());
    
$num=mysql_affected_rows();
    if(
$num>0)
        echo 
"

Il record è stato modificato correttamente</p>"
;
    else
        echo 
"

Errore nella modifica</p>"
;
        echo 
"

Premere sul [url="
."]link[/url] per visualizzare di nuovo i risultati</p>";

                        
mysql_close($db);
                    
?>

Mi dà questi errori:

Warning: Invalid argument supplied for foreach() in /onlineschool/Docenti/insVotiT.php on line 171

Warning: Invalid argument supplied for foreach() in /onlineschool/Docenti/insVotiT.php on line 174

Warning: Invalid argument supplied for foreach() in /onlineschool/Docenti/insVotiT.php on line 178

Warning: Invalid argument supplied for foreach() in /onlineschool/Docenti/insVotiT.php on line 182

Errore nella modifica


Quella parte dei foreach è per me arabo.
Sto fondendo nel cercare di risolverlo... qualcuno mi può dare una mano?