Foros del Web » Programando para Internet » Javascript »

Sacar promedio

Estas en el tema de Sacar promedio en el foro de Javascript en Foros del Web. HOLA NECESITO Q ALGUIEN ME AYUDE PORFA ESTOY HACIENDO UNA PAG PARA REGISTRO DE CALIFICACIONES CON PHP Y MYSQL Y NECESITO Q CUANDO SE INSERTEN ...
  #1 (permalink)  
Antiguo 18/04/2010, 17:38
 
Fecha de Ingreso: diciembre-2009
Mensajes: 48
Antigüedad: 14 años, 4 meses
Puntos: 0
Sacar promedio

HOLA NECESITO Q ALGUIEN ME AYUDE PORFA ESTOY HACIENDO UNA PAG PARA REGISTRO DE CALIFICACIONES CON PHP Y MYSQL Y NECESITO Q CUANDO SE INSERTEN LAS 3 CALIFICACIONES AUTOMATICAMENTE SE PROMEDIEN PERO ESE ES MI PROBLEMA YA Q TODO LO DEMAS FUNCIONA BIEN SOLO FALLA EN LA PARTE DE JAVASCRIPT OJALA ALGUIEN LE PUEDA ECHAR UN OJITO AL CODIGO
GRACIAS..
<HTML>
<HEAD>
<TITLE>.::Registro de Calificaciones::.</TITLE>
<style type="text/css">
<!--
.Estilo1 {font-family: Arial, Helvetica, sans-serif}
-->
</style>


<script type="text/javascript">
function Sumar(){
interval = setInterval("calcular()",1);
}
function calcular(){
uno = document.autoSumForm.calif1$i.value;
dos = document.autoSumForm.calif2$i.value;
tres = document.autoSumForm.calif3$i.value;

document.autoSumForm.promedio$i.value = (((uno * 1) + (dos * 1) + (tres * 1))/3);
}
function NoSumar(){
clearInterval(interval);
}
</script>

</HEAD>
<BODY>
<h1 align="center" class="Estilo1">.:: Registro de Calificaciones ::. </h1>
<h2><br>
<br>
<?

include("Conexion.php");
$con = conectar();



if (!$_POST){
//si no recibo datos de POST, muestro el formulario

//es posible que recibamos un id a partir del que hay que mostrar los datos
if (isset($_GET["id_mostrar"]))
$id_mostrar = $_GET["id_mostrar"];
else
$id_mostrar = 0;

//extraemos de la base de datos los registros a mostrar
//Ejecutamos la sentencia SQL, limitando la búsqueda a 10 registros
// $ssql="select clave, grupo , CONCAT(apellido_p,' ',apellido_m,' ',nombre) AS campos from alumno where grupo>$id_mostrar and grupo=" .$_GET["grupo"] " and materia= " .$_GET["materia"] ;



$ssql="select clave, grupo, nombre, materia, calif1, calif2, calif3, clave_m from calif where grupo>$id_mostrar and ( grupo=" .$_GET["grupo"]. " and clave_m=" .$_GET["combo1"] .")";



$result=mysql_query($ssql, $con);

echo "<form action='calificaciones3.php' method=post>";
echo "\n<table align=center border=1>";


echo "\n<tr bgcolor=#BDBDBD><td><b>No.Cuenta</b></td><td><b>Nombre</b></td><td><b>Grupo</b></td><td><b>Materia</b></td><td><b>Clave</b></td><td><b>Priemero</b></td><td><b>Segundo</b></td><td><b>Tercero</b></td><td><b>Promedio</b></td></tr>";

$i = 1;
while ($fila=mysql_fetch_array($result)){
// echo "\n<input type=hidden name='grupo$i' value='" . $fila["grupo"] . "'>";
echo "<tr>";
//echo "<td>" . $fila["grupo"] . "</td>";




echo "\n<input type=hidden name='materia$i' value='" . $fila["materia"] . "'>";
echo "<td>" . $fila["materia"] . "</td>";


echo "\n<input type=hidden name='clave_m$i' value='" . $fila["clave_m"] . "'>";
echo "<td>" . $fila["clave_m"] . "</td>";



echo "<td><input type=text id='calif1$i' name='calif1$i' size='5' value='" . $fila["calif1"] . "' onFocus='Sumar();' onBlur='NoSumar();'></td>";
echo "<td><input type=text id='calif2$i' name='calif2$i' size='5' value='" . $fila["calif2"] . "' onFocus='Sumar();' onBlur='NoSumar();'></td>";

echo "<td><input type=text id='calif3$i' name='calif3$i' size='5' value='" . $fila["calif3"] . "' onFocus='Sumar();' onBlur='NoSumar();'></td>";

echo "<td><input type=text id='promedio$i' name='promedio$i' size='5' value='" . $fila["promedio"] . "' onFocus='Sumar();' onBlur='NoSumar();' ></td>";
echo "</tr>";
$i++;
$ultimo_mostrado = $fila["grupo"];
}

echo "\n<tr><td colspan=6 align=center><input type='submit' value='Guardar'></td></tr>";
echo "\n</table>";
echo "\n</form>";

//si se han mostrado registros, pongo el enlace para ver los siguientes
if (isset($ultimo_mostrado))
echo "\n<br><a href='calificaciones.php?id_mostrar=" . $ultimo_mostrado . "'></a>";
}else{

//es que he recibido datos de formulario, entonces tengo que recibirlos y actualizar la base de datos
for ($i=1;$i<=10;$i++){
//para cada uno de los elementos que puede haber en el formulario
if (isset($_POST["clave" . $i])){
//es que este registro estaba en el formulario
$clave = $_POST["clave" . $i];
$grupo = $_POST["grupo" . $i];
$calif1 = $_POST["calif1" . $i];
$calif2 = $_POST["calif2" . $i];
$calif3 = $_POST["calif3" . $i];


//$ssql = "update alumno set nombre='$nombre' where grupo=$grupo";

$ssql= "update calif set calif3='$calif3' where clave=$clave and clave_m=$clave_m";
if (mysql_query($ssql, $con))
echo "<br>Registro éxitoso";
else
echo "<br>Falla en el registro";
}
}
echo "\n<p><a href=calificaciones3.php>Volver</a>";
}
?>
</h2>
</BODY>
</HTML>

Etiquetas: promedio
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:50.