In this code I try to get values of checkbox
selected, within a loop, and in another nested loop you get values of inputs
fixed.
With these iterated values obtained within the loops, I wanted to execute a delete
, setting as parameters where
the values of each alumno
selected and the grupos
that are values of predefined inputs.
I tried to execute the query
with the values of n checkbox
that have been selected and with their respective groups, but it is not enough to execute it for all the found records, it seems to me it is a logic error in the loops.
The problem is that the statement is not executed for all selected checkbox
values. For example, if 40 were selected, the delete is only executed for 34,
$alumno = $_POST["idalumno"]; //arreglo [] de alumnos (recogiendo id de arreglo de checkbox)
$idgrupo = $_POST["idgrupo"]; //arreglo [] de grupos, inputs (hidden)
for ($i=0; $i < count($alumno); $i++) { //mientras la variable sea menor al tamaño de arreglo va aumentando de uno en uno
$alum = $alumno[$i]; //obteniendo cada idalumno
for ($a=0; $a < count($idgrupo); $a++) {
$gpo = $idgrupo[$a]; //obteniendo id de cada grupo
$verifica = "SELECT * FROM alumno_grupo WHERE idAlumno = '{$alum}' and idGrupo = '{$gpo}'";
$consul = mysqli_query($conexion, $verifica)or die (mysqli_error($conexion));
$num_rows = mysqli_num_rows($consul);
if ($num_rows > 0) {
$cons = "DELETE FROM alumno_grupo WHERE idAlumno = '{$alum}' AND idGrupo = '{$gpo}'";
$consulta = mysqli_query($conexion, $cons)or die (mysqli_error($conexion));
if ($consulta){
?>
<script>
alert('ALUMNO DADO DE BAJA DE LOS GRUPOS-MATERIA, CORRECTAMENTE')
location.href = "../View/Admin/baja_alum.php";
</script>
<?php
} else { //si no se ejecuta la consulta
?>
<script>
alert('ATENCION !!!! ERROR AL ELIMINAR')
location.href = "../View/Admin/baja_alum.php";
</script>
<?php
}
} else { //si no se encuentran los registros
?>
<script>
alert('ATENCIÓN!!: NO SE ENCONTRO REGISTRO CON ESE ALUMNO Y GRUPO-MATERIA')
location.href = "../View/Admin/baja_alum.php";
</script>
<?php
} //else
} //for
} //for