PHP - Ayuda con ejemplo

 
Vista:
sin imagen de perfil

Ayuda con ejemplo

Publicado por Ericsson (77 intervenciones) el 15/07/2014 19:50:12
Hola amigos no se si me pudieran ayudar con este ejemplo
he encontrado este ejemplo que se adapta a mi necesidad


con este codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$mysqli = new mysqli('localhost', 'root','root', 'siadace01' );
$sql = "SELECT V_codi_est,V_nombre,V_apellido FROM tb_estudiantes";
$consulta = $mysqli->query($sql);
?>
<form action="guardar.php" method="post">
<table width="314" border="1">
 
  <tr>
    <td height="26" colspan="2">LISTA DE ESTUDIANTES </td>
    </tr>
  <tr>
    <td width="137"><strong>Guardar Notas</strong></td>
    <td width="161" height="26"><input type="submit" value="Guardar" /></td>
    </tr>
</table>
 
<table cellpadding="0" cellspacing="5" border="0" class="bordered-table zebra-striped" id="registro">
	<thead>
		<tr bgcolor="#a6cbea">
			<th>Dui</th>
			<th>Nombre</th>
			<th>Apellido</th>
<!--            <th><font color="blue">Modificar</font></th>
-->            <th><font color="red"> (Seleccionar)</font></th>
   	  </tr>
	</thead>
	<tbody>
	<?php
		while ($filas = $consulta->fetch_assoc())
		{
 
			echo '<tr>';
			echo '<td ><a><font color="black">'.utf8_encode ($filas['V_codi_est']).'</a></td>';
			echo '<td><a><font color="black">'.utf8_encode ($filas['V_nombre']).'</a></td>';
			echo '<td><a><font color="black">'.utf8_encode ($filas['V_apellido']).'</a></td>';
			//echo '<td ><a href=../form_act_personal.php?dui='.$filas['V_codi_est'].'><font color="blue">'.utf8_encode ('MODIFICAR').'</a></td>';
            echo '<td><input type="checkbox" name="casilla[]" value='.utf8_encode ($filas['V_codi_est']).'></td>';
			echo '<td><input type="text" name="nota1" size="2" ></td>';
			echo '<td><input type="text" name="nota2" size="2"></td>';
			echo '<td><input type="text" name="nota3" size="2"></td>';
echo '</tr>';
				}
	?>
<tbody>
</table>
</form>
AQUI ME GENERA CASILLAS PARA PODER INTRUDUCIR DATOS CON OTRO ARCHIVO LOS QUIERO ALMACENAR

ASI:
GUARDA:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
 
include 'conexion.php';
 
$con=conexion();
 
$x=$_POST[casilla];
$not1=$_POST[nota1];
$not2=$_POST[nota2];
$not3=$_POST[nota3];
 
foreach ($x as $value){
 
 $res=mysql_query("INSERT INTO `tb_notas`(`V_codi_est`,`C_id_asignatura`,`C_per_tri`,`F_nota_1`,`F_nota_2`,`F_nota_3`,V_anio_lect) VALUES ('$value','a','b','$not1','$not2','$not3','2014')",$con);
if($res){
 
echo 'Dato eliminado correctamente<br />';
 
 }
 
}
 
?>

<a href="javascript:history.go(-1)"><center>Pagina Atr&aacute;s</center></a>
PERO EL DETALLE ES QUE SOLO ME GUARDA EL ULTIMO VALOR EN TODOS LOS REGISTROS PERO LOS CODIGOS ME LOS ALMACENA CORRECTAMENTE PERO NO LAS NOTAS.

ASI SE LLENA MI TABLA: PERO NO ESTA BIEN QUIERO QUE SE ME LLENE CON LOS DATOS Q ESCRIBO EN LA PRIMER PANTALLA



QUISE BORRAR OTRO TEMA Q ABRI DE REFERENTE A ESTO PERO NO PUDE ESPERO ME COMPRENDAN
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Daniel

Ayuda con ejemplo

Publicado por Daniel (3 intervenciones) el 23/07/2014 03:14:52
El error esta que todos las cajas de textos se llaman nota1, nota2, nota3 por eso guarda el ultimo valor para eso haz un recorrido de la tabla o cambia el name de los textos podria ser de esta forma

$id=1;
while ($filas = $consulta->fetch_assoc())
{

echo '<td><input type="text" name="nota1'.$i.'" size="2" ></td>';
echo '<td><input type="text" name="nota2'.$i.'" size="2"></td>';
echo '<td><input type="text" name="nota3'.$i.'" size="2"></td>';
$i++;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar