I have in a table stored the grades and number of absences of three periods, of students. These were sent by an arrangement sending in the same the qualification and the absences: partial1 [0] = qualification, partial1 [1] = non-attendance. Now what I was trying to do was to send from an input a number of classes taught in the semester, and in an array of inputs the number of total assistances in the semester of each student captured will be sent.
Within a cycle calculate the average of those 3 partial (sending the grades shown from the same table where they are printed) per student, then apply a rule of 3 within another cycle that calculates the percentage of assists based on the classes taught and the number of assistances for each student, sent and received in arrangement. Save that percentage as an integer in another field of the table (assists).
Then compare that value of the percentage obtained and if it is equal to or greater than 80 that is stored the average calculated before, if less than the average is 5.
The errors it generates are:
PHP Notice: Undefined offset: 1707 in /home/platafo6/public_html/View/Docente/Capt_Calif.php on line 135
PHP Notice: Undefined offset: 1707 in /home/platafo6/public_html/View/Docente/Capt_Calif.php on line 135
I think it's more logical problem ... accommodate the variables correctly and the keys of the cycles.
<?php
require_once '../../Model/Conexion.php';
require_once '../../Model/Model_Docentes.php';
//$connect = conectar(); //conexion a la bd
$conexion = conectar();
//si esta puesto el boton de enviar, si el array de los id grupos y el de idalumno no esta vacio
if ( isset($_POST['formAlumno']) && !empty($_POST['idgpo']) && !empty($_POST['idalumno']) ) {
//recogirndo arrays
//////////////////////////////////////////////////////
$grupo = $_POST['idgpo'];
$alumno = $_POST['idalumno'];
////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CAPTURANDO PARCIAL 1
if(isset($_POST['parcialP1'])) {
$parcialP1 = $_POST['parcialP1'];
$n = count($parcialP1);
$num_alumno = 1; //contador de registros de alumno en gpo
for ($i=1; $i < $n; $i += 2, ++$num_alumno) { //pre-incremento de 2 y bucle para primer parcial
$p1 = $parcialP1[$i - 1]; //calificación
$inasisP1 = $parcialP1[$i]; //numero inasistencias
$gpo = $grupo[$num_alumno - 1];
$al = $alumno[$num_alumno - 1];
//consulta update para colocar las caliicaciones e inasiatencias, where con valores de grupo y alumno
$sql1 = mysqli_query($conexion, "UPDATE alumno_grupo SET parcial1 = '{$p1}', inasisP1 = '{$inasisP1}'
WHERE idAlumno = '{$al}' AND idGrupo = '{$gpo}'") or die (mysqli_error($conexion));
if ($sql1) {
?>
<script>
alert('Calificaciones Capturadas Correctamente')
location.href = "Grupos.php";
</script>
<?php
}
} //fin for P2
} //FIN ISSET
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////CAPTURANDO PARCIAL 2
if(isset($_POST['parcialP2'])) {
$parcialP2 = $_POST['parcialP2'];
$n2 = count($parcialP2);
$num2_alumno = 1; //contador de registros de alumno en gpo
for ($i=1; $i < $n2; $i += 2, ++$num2_alumno) {
$p2 = $parcialP2[$i - 1];
$inasisP2 = $parcialP2[$i];
$gpo = $grupo[$num2_alumno - 1];
$al = $alumno[$num2_alumno - 1];
//consulta update para colocar las caliicaciones e inasiatencias, where con valores de grupo y alumno
$sql2 = mysqli_query($conexion, "UPDATE alumno_grupo SET parcial2 = '{$p2}', inasisP2 = '{$inasisP2}'
WHERE idAlumno = '{$al}' AND idGrupo = '{$gpo}'") or die (mysqli_error($conexion));
if ($sql2) {
?>
<script>
alert('Calificaciones Capturadas Correctamente')
location.href = "Grupos.php";
</script>
<?php
}
} //fin for P2
} //FIN ISSET
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //CAPTURANDO PARCIAL 3
if(isset($_POST['parcialP3'])) {
$parcialP3 = $_POST['parcialP3'];
$n3 = count($parcialP3);
$num3_alumno = 1; //contador de registros de alumno en gpo
for ($i=1; $i < $n3; $i += 2, ++$num3_alumno) {
$p3 = $parcialP3[$i - 1];
$inasisP3 = $parcialP3[$i];
$gpo = $grupo[$num3_alumno - 1];
$al = $alumno[$num3_alumno - 1];
//consulta update para colocar las caliicaciones e inasiatencias, where con valores de grupo y alumno
$sql3 = mysqli_query($conexion, "UPDATE alumno_grupo SET parcial3 = '{$p3}', inasisP3 = '{$inasisP3}'
WHERE idAlumno = '{$al}' AND idGrupo = '{$gpo}'") or die (mysqli_error($conexion));
if ($sql3) {
?>
<script>
alert('Calificaciones Capturadas Correctamente')
location.href = "Grupos.php";
</script>
<?php
}
} //fin for P2
} //FIN ISSET
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CALCULO DE PROMEDIOS DE ALUMNO Y % DE ASISTENCIAS
if ( isset($_POST['numsesiones']) && isset($_POST['asistotales']) ) {
$asistotales = $_POST['asistotales']; //valores de arreglo recibido
$numsesiones = $_POST['numsesiones']; //valor recibido de un input
$parcial1 = $_POST['parcialP1']; //arreglo parcial1[] =[calif][inasis][calif][inasis]
$parcial2 = $_POST['parcialP2']; //arreglo parcial2[] =[calif][inasis][calif][inasis]
$parcial3 = $_POST['parcialP3']; //arreglo parcial3[] =[calif][inasis][calif][inasis]
/////////////////////////////////////////////////////////////////////////////////////////////////////
$tamaP1 = count($parcial1);
$tamaP2 = count($parcial2);
$tamaP3 = count($parcial3);
$num_alumno1 = 1;
for ($i1 = 1; $i1 < $tamaP1; $i1 += 2, ++$num_alumno1) { //for calcula promedios por alumno
$p1b = $parcial1[$i1 - 1]; //P1
$idgpo = $grupo[$num_alumno1 - 1]; //LINEAS DE ERROR
$idalu = $alumno[$num_alumno1 - 1]; //134
$num_alumno2 = 1;
for ($i2 = 1; $i2 < $tamaP2; $i2 += 2, ++$num_alumno2) { //for calcula promedios por alumno
$p2b = $parcial2[$i2 - 1]; //P1
$idgpo = $grupo[$num_alumno2 - 1];
$idalu = $alumno[$num_alumno2 - 1];
$num_alumno3 = 1;
for ($i3 = 1; $i3 < $tamaP3; $i3 += 2, ++$num_alumno3) { //for calcula promedios por alumno
$p3b = $parcial2[$i3 - 1]; //P1
$idgpo = $grupo[$num_alumno3 - 1];
$idalu = $alumno[$num_alumno3 - 1];
$sumab = $p1b+$p2b+$p3b;
$nb = 3;
$promediob = $sumab/3;
$promediob = round($promediob); //redondeando de .5 hacia abajo y .5 hacia arriba
$sql = mysqli_query($conexion, "UPDATE alumno_grupo SET final = '{$promediob}'
WHERE idAlumno = '{$idalu}' AND idGrupo = '{$idgpo}'") or die (mysqli_error($conexion));
} //for p3
} //for p2
} //for p1
$n4 = count($asistotales); //cuenta elementos del array de asistencias
$num4_alumno = 1; //contador de registros de alumno en gpo
for ($i=0; $i < $n4; $i++, ++$num4_alumno) {
//regla de 3
$a = $asistotales[$i];
$regla = $a * 100;
$asis = $regla/$numsesiones; //porcentaje de asistencia
$asis = round($asis); //redondeamos de: .5 hacia abajo de .5 hacia arriba el porcentaje de asistnecia
$idgpo = $grupo[$num4_alumno - 1]; //-1 porque el array recibe (calificacion,inasistencia)
$idalu = $alumno[$num4_alumno - 1]; //inicializa en 1 = inasistencia, -1 = calificacion
//insertamos el porcentaje total de asistencia redondeado a entero
$sqla = mysqli_query($conexion, "UPDATE alumno_grupo SET asistencias = '{$asis}'
WHERE idAlumno = '{$idalu}' AND idGrupo = '{$idgpo}'") or die (mysqli_error($conexion));
//RESTRICCIONES DEL 80% DE ASISETENCIA
if ($asis < 80) { //DE SER MENOR DEL 80
$sqlb = mysqli_query($conexion, "UPDATE alumno_grupo SET final = 5
WHERE idAlumno = '{$idalu}' AND idGrupo = '{$idgpo}'") or die (mysqli_error($conexion));
} /*elseif ($asis >= 80) { //else DE SER IGUAL O MAYOR AL 80
$sqlc = mysqli_query($conexion, "UPDATE alumno_grupo SET final = '{$promediob}'
WHERE idAlumno = '{$idalu}' AND idGrupo = '{$idgpo}'") or die (mysqli_error($conexion));
}*/
} //fin for asistencias
} //if empty && isset
//////////////////////// FINAL /////////////////////////////////////////////////////////////////////////////////////////////////////////
} //fin if isset formAlumno, idgpo e idalumno
?>