What this code does is to receive in a variable the number of classes taught, in array
the number of absences for each student, in another'array' the idGroup, which is always the same, and in another array
receives the idAlumno, these data are sent from a table as a form.
What I was trying to do is that based on num. of sessions and assistances by means of a rule of 3 to calculate the percentage of attendance obtained from each student.
This part seems to work well, but apart you have to calculate the average of 3 grades of each student, these grades are retrieved from the database, you must evaluate if the percentage of attendance of each student is greater than or equal to 80, save in the corresponding record the average obtained previously, of being less than 80 must have a failing grade = 5.
What he managed to do well is the jump from registration to registration, to make those calculations in each one of them. I was trying to do it by initializing a variable with the first idAlumno
found and then compare it in the loop if it is the same as that recovered by another variable. It's more of a logic error.
//CALCULO DE PROMEDIOS DE ALUMNO Y % DE ASISTENCIAS
elseif( (isset($_POST['numsesiones']) ) && (!empty($_POST['asistotales'])) ) {
$grupo4 = $_POST['idgpo']; //arreglo idgrupo[] siempre es el mismo
$gpo4 = $grupo4[0]; //el idGrupo es el mismo en todo el arreglo
$alumno4 = $_POST['idalumno']; //arreglo idalumno[]
$consulta1 = "SELECT A.matricula, A.nombre, AG.parcial1, AG.parcial2, AG.parcial3, AG.final, AG.idAlumno, AG.idGrupo FROM alumno A, alumno_grupo AG, materias M, periodos Pr, profesores P, grupos G WHERE M.idMateria = G.materia and A.idAlumno = AG.idAlumno and G.idGrupo = AG.idGrupo and G.profesor = P.idProfesor and G.periodo = Pr.idPeriodo and AG.idGrupo = $gpo4 ORDER BY A.nombre";
$res = mysqli_query($conexion,$consulta1);
$res2 = mysqli_query($conexion,$consulta1);
$fila = $res->fetch_assoc(); //array asociativo para obtener el primer registro de alumno
$fila2 = $res2->fetch_assoc(); //array asociativo para obtener los demas registros
$nalumno = count($alumno4); //cuenta los elementos del arreglo de los id alumno[]
$asistenciasalumno = $_POST['asistotales']; //valores de arreglo recibido
$numsesiones = $_POST['numsesiones']; //1 valor recibido de un input
$bandera = $fila['idAlumno']; //asignamos a variable el primer registro de alumno encontrado
for ($a = 0; $a < $nalumno; $a++) { //for recorre elementos del array[] idAlumno
$alum = $alumno4[$a]; //variable toma valor del arreglo en el id
$gpos = $grupo4[$a]; //variable toma el valor del arreglo de idgrupo, (siempre es el mismo)
//asignanle a variable el indice del arreglo
$asis = $asistenciasalumno[$a];
$regla = $asis * 100;
$asis = $regla/$numsesiones; //regla de 3 para sacr porcentaje de asistencia,
$asis = round($asis);
echo $asis; //prueba
echo "<br>"; //prueba
$sqlp = mysqli_query($conexion, "UPDATE alumno_grupo SET asistencias = '{$asis}'
WHERE idAlumno = '{$alum}' AND idGrupo = '{$gpos}'") or die (mysqli_error($conexion));
while ($fila2 = $res2->fetch_assoc()) {
if($bandera == $fila2['idAlumno']) { //si la bandera es igual al primer idAlumno
//obteniendo las calificaciones de los 3 parciales por alumno
$p1b = $fila2['parcial1'];
$p2b = $fila2['parcial2'];
$p3b = $fila2['parcial3'];
$suma = $p1b+$p2b+$p3b;
$promedio = $suma/3;
} else {
$p1b = $fila2['parcial1'];
$p2b = $fila2['parcial2'];
$p3b = $fila2['parcial3'];
$suma = $p1b+$p2b+$p3b;
$promedio = $suma/3;
}
$bandera = $fila['idAlumno'];
}
if ($asis >= 80) { //DE SER MENOR EL % DE ASSITENCIAS OBTENIDO DEL 80
$sqlb = mysqli_query($conexion, "UPDATE alumno_grupo SET final = '{$promedio}'
WHERE idAlumno = '{$alum}' AND idGrupo = '{$gpos}'") or die (mysqli_error($conexion));
} elseif ($asis < 80) {
$sqlb = mysqli_query($conexion, "UPDATE alumno_grupo SET final = 5
WHERE idAlumno = '{$alum}' AND idGrupo = '{$gpos}'") or die (mysqli_error($conexion));
}
} //for recorre
} //if empty numsesiones && isset asistotales/