Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/06/2008, 14:42
chelohc
 
Fecha de Ingreso: mayo-2008
Mensajes: 12
Antigüedad: 16 años, 9 meses
Puntos: 0
Exclamación insertar javascript dentro un bucle while en php

Alguien q me pueda ayudar!!!!, bueno estas es la idea tengo una tabla con 6 campos numero, nombre, conocimiento, precision, procedimiento y total, los nombres voy recuperando de mi base de datos con un while y los campos conocimiento, precision y procedimiento voy llenando mediante un formulario y con un javascript voy sumando los 3 campos y poniendo mi resultado automaticamente en mi campo "total" esta es la idea:

conocimiento precision procedimiento total
12 12 12 36
2 2 2 6
..............
.....
el problema es q la sumatoria no funciona cuando es mas de 1 fila solo funciona con una fila aqui les pongo el cod



Código PHP:
<FORM name"frm" action="insertarNota.php?CodUsuario=<?php echo $lin['CodUsuario']; ?>&CodDocente=<?php echo $lin['CodDocente']; ?>&CodMateria=<?php echo $usuario_datos['CodMateria']; ?>&Grupo=<?php echo $datos['Grupo']; ?>" method=post>
<table width="100%"  border="1" cellspacing="0" cellpadding="0" bgcolor="#CCCCCC">
  <tr>
    <td colspan="2"><font  size="2" face="Arial">Nivel: <?php echo $usuario_datos['NombreNivel']; ?></font></td>
  
    <td colspan="4"><CENTER><font  size="2" face="Arial">PRIMER PARCIAL</font></CENTER></td>
    
   
  </tr>
  <tr>
 
    <td colspan="2"><font  size="2" face="Arial">Docente: <strong><?php echo $lin['Nombre']; ?> <?=$lin['ApellidoPaterno']?>  <?=$lin['ApellidoMaterno']?></strong></font></td>
 
    <td colspan="3"><CENTER><font  size="2" face="Arial">LOGRO DE<BR>CAPACIDADES</font></CENTER></td>
    <td width="5%"><CENTER><font  size="1" face="Arial">NOTA<BR>FINAL</font></CENTER></td>
    
  
  </tr>
  <tr>
    <td width="5%"><CENTER><font  size="1" face="Arial">CODIGO<BR> ESTUDIANTE</font></CENTER></td>
    <td width="30%"><CENTER><font  size="2" face="Arial">NOMINA</font></CENTER></td>
 
    <td width="5%"><CENTER><font  size="1" face="Arial">Conocim<BR>1 a 20</font></CENTER></td>
    <td width="5%"><CENTER><font  size="1" face="Arial">Precisio<BR>1 a 20</font></CENTER></td>
    <td width="5%"><CENTER><font  size="1" face="Arial">Procedi<BR>1 a 30</font></CENTER></td>
    <td width="5%"><CENTER><font  size="1" face="Arial">Total</font></CENTER></td>
    
    
  </tr>

 <?php $sq="SELECT DISTINCT e.Nombre, e.ApellidoPaterno, e.ApellidoMaterno, e.CodEstudiante, em.Grupo
                    FROM usuario u, docente d, docentemateria dm, materia m, estudiantemateria em, estudiante e, areahumanidades ah, areatecnicas at, nivel n
                    WHERE d.CodUsuario = u.CodUsuario and m.CodNivel=n.CodNivel and d.CodDocente = dm.CodDocente and m.CodMateria=em.CodMateria and em.CodEstudiante=e.CodEstudiante and
                    e.CodUsuario=ah.CodEstudiante and e.CodUsuario=at.CodEstudiante and d.CodDocente = '"
.$_GET['CodDocente']."' and m.CodMateria = '".$_GET['CodMateria']."' and em.Grupo = '".$_GET['Grupo']."'
                    ORDER BY e.ApellidoPaterno ;"
;
                    
$rest mysql_query ($sq) or die (mysql_error());
                    
$cont=1;
                     while( 
$datos mysql_fetch_array($rest))
    {
    if(
$colorfila==0)
        {
                    
$color"#DEDEBE";
                    
$colorfila=1;
                }else{
                    
$color"#F0F0F0";
                    
$colorfila=0;
        }
    
?>
    
  <tr bgcolor=<?php echo $color?>>
    <td height="30"><?php echo $cont ++?></td>
    <td><?php echo $datos['ApellidoPaterno']; ?> <?php echo $datos['ApellidoMaterno']; ?> <?php echo $datos['Nombre']; ?> </td>
<script languaje="javascript"> 
function suma(){ 
var vtemp=0 
vresult=0 

    for (var i=1;i<4;i++)
    { // hace un bucle para calcular todos los valores
         vtemp=eval("parseFloat(document.all.primero"+i+".value)") 
        if(!isNaN(vtemp)) vresult+=vtemp // si valor es número negativo, añadir
    } 
    
    
document.all.result.value=vresult // cambia el último valor...Resultado uno



</script>

    <td><input name="primero1" type="text" class="tableResults" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" onkeyup="suma()" size=2 maxlength="2" /> </td>
    <td><input name="primero2" type="text" class="tableResults" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" onkeyup="suma()" size=2 maxlength="2" /></td>
    <td><input name="primero3"  type="text" class="tableResults" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" onkeyup="suma()" size=2 maxlength="2" /></td>
    <td><input name="result" type="text" value="" size="2" readonly="readonly"></td>

  
    
    
    
    
  </tr>
  <?php 
 
}
 
?>
</table>
 <input name=estudiante type=hidden value='<?php echo $datos['CodEstudiante']; ?>'  >
 <input name=materia type=hidden value='<?php echo $usuario_datos['CodMateria']; ?>'  >
 <br><br>

<center>  <input name="notas" type="submit" class="submitInput" value="INSERTAR CALIFICACION" >
<input type="reset" class="submitInput"  value="CANCELAR "  >
</center>
 </FORM>