Código:
<?php if($_POST[mostrar]){ $sql6 = "select * from materia where Id = '".$_POST[materia]."'"; $resultado2 = mysql_query ($sql6); $row2 = mysql_fetch_array($resultado2); echo $row2['Descripcion']; $resultado=mysql_query($sql5= "SELECT alumno.Rut, alumno.Nombre as nombrea, alumno.Apellido as apellidoa, alumno.N_lista as nlista, alumno.Curso, notas.Id as Id, notas.Rut_alumno, notas.Id_materia, notas.Semestre, notas.Ano, notas.nota1 as nota1, notas.nota2 as nota2, notas.nota3 as nota3, notas.nota4 as nota4, notas.nota5 as nota5, notas.nota6 as nota6, notas.nota7 as nota7, notas.nota8 as nota8, notas.nota9 as nota9, notas.nota10 as nota10 FROM alumno Inner Join notas ON notas.Rut_alumno = alumno.Rut WHERE alumno.Curso = '".$_POST[curso]."' AND notas.Semestre = '".$semestre."' AND notas.Ano = '".$ano."' AND notas.Id_materia = '".$_POST[materia]."' ORDER BY alumno.N_lista"); ?> <table border="1" cellspacing="0"> <tr> <td width="20">Nº </td> <td width="200">Apellidos</td> <td width="200">Nombres</td> <td width="47">Nota 1</td> <td width="47">Nota 2</td> <td width="47">Nota 3</td> <td width="47">Nota 4</td> <td width="47">Nota 5</td> <td width="47">Nota 6</td> <td width="47">Nota 7</td> <td width="47">Nota 8</td> <td width="47">Nota 9</td> <td width="55">Nota 10</td> </tr> <?php while($row = mysql_fetch_array($resultado)) { printf("<tr><td>".$row["nlista"]."</td><td>".$row["apellidoa"]."</td><td>".$row["nombrea"]."</td><td><input type='text' name='nota1' id='nota1".$row["Id"]."' value='".$row["nota1"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota2' id='nota2".$row["Id"]."' value='".$row["nota2"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota3' id='nota3".$row["Id"]."' value='".$row["nota3"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota4' id='nota4".$row["Id"]."' value='".$row["nota4"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota5' id='nota5".$row["Id"]."' value='".$row["nota5"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota6' id='nota6".$row["Id"]."' value='".$row["nota6"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota7' id='nota7".$row["Id"]."' value='".$row["nota7"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota8' id='nota8".$row["Id"]."' value='".$row["nota8"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota9' id='nota9".$row["Id"]."' value='".$row["nota9"]."' size='3' maxlength='3'/></td><td><input type='text' name='nota10' id='nota10".$row["Id"]."' value='".$row["nota10"]."' size='3' maxlength='3'/></td></tr>"); } ?> </table> <tr> <td> </td> <td> </td> <td> </td> <td><input type="submit" name="grabar" id="grabar" value="Grabar Cambios" /> <?php } ?> <!--aqui termina la condicion if post[mostrar] --> </td> </tr> </table> <!--desde aqui grabaria los datos --> <?php if($_POST[grabar]){ $resultado=mysql_query($sql5= "SELECT alumno.Rut, alumno.Nombre as nombrea, alumno.Apellido as apellidoa, alumno.N_lista as nlista, alumno.Curso, notas.Id as Id, notas.Rut_alumno, notas.Id_materia, notas.Semestre, notas.Ano, notas.nota1 as nota1, notas.nota2 as nota2, notas.nota3 as nota3, notas.nota4 as nota4, notas.nota5 as nota5, notas.nota6 as nota6, notas.nota7 as nota7, notas.nota8 as nota8, notas.nota9 as nota9, notas.nota10 as nota10 FROM alumno Inner Join notas ON notas.Rut_alumno = alumno.Rut WHERE alumno.Curso = '".$_POST[curso]."' AND notas.Semestre = '".$semestre."' AND notas.Ano = '".$ano."' AND notas.Id_materia = '".$_POST[materia]."' ORDER BY alumno.N_lista"); $datos=array(); $fila=0; while($row= mysql_fetch_assoc($resultado)){ $datos[$fila]['nota1']= $_POST['nota1'.$row["Id"]]; $datos[$fila]['nota2']= $_POST['nota2'.$row["Id"]]; $datos[$fila]['nota3']= $_POST['nota3'.$row["Id"]]; $datos[$fila]['nota4']= $_POST['nota4'.$row["Id"]]; $datos[$fila]['nota5']= $_POST['nota5'.$row["Id"]]; $datos[$fila]['nota6']= $_POST['nota6'.$row["Id"]]; $datos[$fila]['nota7']= $_POST['nota7'.$row["Id"]]; $datos[$fila]['nota8']= $_POST['nota8'.$row["Id"]]; $datos[$fila]['nota9']= $_POST['nota9'.$row["Id"]]; $datos[$fila]['nota10']= $_POST['nota10'.$row["Id"]]; $fila++; } foreach($datos as $valor) { $sql9= "INSERT INTO notas (nota1, nota2, nota3, nota4, nota5, nota6, nota7, nota8, nota9, nota10) VALUES (".$valor['nota1'].",".$valor['nota2'].",".$valor['nota3'].",".$valor['nota4'].",".$valor['nota5'].",".$valor['nota6'].",".$valor['nota7'].",".$valor['nota8'].",".$valor['nota9'].",".$valor['nota10'].")"; $ingreso = mysql_query ($sql9); } } ?> </form> </body> </html>