What this code does is print the materials with grades of a group of students requested in PDF, a page printed as a ballot for each student.
Within the loop there is a if
comparing a variable $bandera
initialized with the first idAlumno
recovered from a array asociativo
with the first value of idAlumno
recovered from the query, if they match print the notes of the first student and in the else it prints the data of the other students.
This part works well, the problem is that when you want to print the notes of certain groups, which already have registered grades so the contadores
of records in the loop that work as a divisor to calculate average, should work, Mark this error:
'Warning: Division by zero in C: \ xampp \ htdocs \ cebProcedure \ pdfphp \ reportTiraBoleta.php on line 170
Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Some data has already been output, can not send PDF file' in C: \ xampp \ htdocs \ cebProcedular \ pdfphp \ fpdf \ fpdf.php: 271 Stack trace: # 0 C: \ xampp \ htdocs \ cebProcedular \ pdfphp \ fpdf \ fpdf.php (1063): FPDF-> Error ('Some data has a ...') # 1 C: \ xampp \ htdocs \ cebProcedular \ pdfphp \ fpdf \ fpdf.php (999): FPDF-> _checkoutput () # 2 C: \ xampp \ htdocs \ cebProcedular \ pdfphp \ reportTiraBoleta.php (273): FPDF-> Output () # 3 { main} thrown in C: \ xampp \ htdocs \ cebProcedular \ pdfphp \ fpdf \ fpdf.php on line 271 '
This only when certain groups are requested, I think it would be logical error the loop printing variable $rpromedio
, accommodate it in another place of the loop.
In the code I comment some lines.
<?php
if( isset($_GET['periodo']) && isset($_GET['semestre']) && isset($_GET['grupo']) ) {
$periodo = $_GET['periodo']; //RECIBIMOS EL PARAMETRO POR URL : EL ID DE LA TABLA ALUMNO_GRUPO
$semestre = $_GET['semestre'];
$grupo = $_GET['grupo'];
}
//////////////////////////////////////CONSULTA TRAE TODAS LAS CALIFICACIONES DE TODOS LOS ALUMNOS PERYECIENTES A CIERTO GRUPO,
$consulta = "SELECT A.idAlumno, A.matricula, A.nombre, A.grupo, P.periodo, AG.parcial1 as p1mat, AG.inasisP1 as ina1mat, M.materia, M.idMateria, G.idGrupo, P.descripcion, A.semestre, G.capacitacion, M.areaComponente, P.descripcion FROM alumno A, alumno_grupo AG, grupos G, materias M, periodos P WHERE A.idAlumno = AG.idAlumno and G.idGrupo = AG.idGrupo and M.idMateria = G.materia and P.idPeriodo = G.periodo and P.periodo = $periodo and A.semestre = $semestre and A.grupo = $grupo ORDER BY A.nombre";
//////////////////////////////////////////////////////////////////////////////////////////////////////////
$res=$mysqli->query($consulta);
$res2=$mysqli->query($consulta);
$pdf = new PDF();
$pdf->Addpage();
$pdf->AliasNbPages();
//////////////////////////////////////////////////////////////////////////////////////////
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',8);
$pdf->Ln(18);
////////////////////////////////////////////////////// COLOCANDO ENCABEZADOS EN PAGINA
$pdf->SetX(22);//posisionamos en 10 de x DATOS DE LA PRIMERA HOJA RECUPERADA CON LAS CALIFS DE UN ALUMNO
$pdf->Cell(109,6,'UNIDAD ACADEMICA CURRICULAR',1,0,'C',1);//colocando ancho de celda
$pdf->SetX(132);//posisionamos en 10 de x
$pdf->Cell(25,6,'INASISTENCIAS',1,0,'C',1);//
$pdf->SetX(158);
$pdf->Cell(24,6,'CALIFICACION',1,0,'C',1);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// IMPRIMIENDO LOS VALORES DE LA TABLA //////////////////////////////
$fila1 = $res->fetch_assoc(); //array asociativo de la consulta
$bandera = $fila1['idAlumno']; //variable flag a la que se le asigna el idAlumno del primer registro
$suma = 0; //inicializando la variable que ira sumando las calificaciones
$promedio = 0; //iniciaizando variable que almacenara el promedio
$pdf->SetXY(19,30);//posisionamos en 10 de x
$pdf->Cell(25,5,$fila1['matricula'],1,0,'C',1);
//NOMBRE ALUMNO COLPLETO
$pdf->SetX(47);//posisionamos en 10 de x
$pdf->Cell(100,5,$fila1['nombre'],1,0,'C',1);//colocando ancho de celda
//SEMESTRE
$pdf->SetX(150);//posisionamos en 10 de x
$pdf->Cell(9,5,$fila1['semestre'],1,0,'C',1);
//PERIODO
$pdf->SetX(161);//posisionamos en 10 de x
$pdf->Cell(24,5,$fila1['descripcion'],1,0,'C',1);
//CAPACITACION DONDE ESTA INSCRITO
$pdf->Ln();
$pdf->Ln();
$pdf->SetX(78);//posisionamos en 10 de x
$pdf->Cell(40,5,$fila1['capacitacion'],1,0,'C',1);
//NUMERO DE GRUPO
$pdf->SetX(120);//posisionamos en 10 de x
$pdf->Cell(8,5,$fila1['grupo'],1,0,'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->Ln(4.7);
$contador = 0; //contara los registros que tienen el mismo idAlumno (Las calificaciones que le corresponden a cada alumno)
while ($fila = $res2->fetch_assoc()) //recuperando con array asociativo los califs de la tabla
{
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',8);
if ( $bandera == $fila['idAlumno'] ) { //si en los registros recuperados, cada idAlumno es igual a bandera
//imprimir los califs que correcponden a ese alumno
if ($fila['materia'] == 'TUTORIA GRUPAL') { //SI LA MATERIA ES TUTORIA:
if ( $fila['p1mat'] == 10 ) { // Y SI ES 10
$pdf->SetX(22);
$pdf->Cell(109,6, $fila['materia'],1,0,'C');//
$pdf->SetX(132);
$pdf->Cell(25,6, $fila['ina1mat'],1,0,'C');//
$pdf->SetX(158);
$pdf->Cell(24,6, $fila['p1mat']='AC',1,1,'C',0); //IMPRIME AC EN LA BOLETA PDF
} else { //SI NO
$pdf->SetX(22);
$pdf->Cell(109,6, $fila['materia'],1,0,'C');//
$pdf->SetX(132);
$pdf->Cell(25,6, $fila['ina1mat'],1,0,'C');//
$pdf->SetX(158);
$pdf->Cell(24,6, $fila['p1mat']='NA',1,1,'C',0); //IMPRIME NO ACREDITADO EN BOLETA PDF
}
} else {
$pdf->SetX(22); //SI NO ES TUTORIA IMPRIME LA CALIF EN NUMERO
$pdf->Cell(109,6, $fila['materia'],1,0,'C');//
$pdf->SetX(132);
$pdf->Cell(25,6, $fila['ina1mat'],1,0,'C');//
$pdf->SetX(158);
$pdf->Cell(24,6, $fila['p1mat'],1,1,'C',0);
//VERIFICACIÓN DEL CAMPO CAPACITACION PARA DESCARTAR EN EL CALCULO DEL PROMEDIO
//AQUELLOS REGISTROS CON ESTOS VALORES.
//si el campo "capacitacion del registro actual es: paraescolares o tutorias"
if ( ($fila['areaComponente'] == 'Paraescolares') || ($fila['areaComponente'] == 'Tutorias') ) {
$suma = $suma; //suma tendrra el valor anterior
$contador = $contador; //contador tendra el valor anterior
} else {
$valorFila = $fila['p1mat']; //una variable que guardara la calificacion
$suma = $suma + $valorFila; //variable de sumatoria, que agregara el $valorFila
$contador++; //incrementa el contador
}
} // FIN ELSE NO ES TUTORIA
} //FIN IF BANDERA == AL PRIMER ALUMNO
else { //si no corresponden imprime el resto de calificaciones recuperadas en hojas separadas
//que sea un valor variable dependiendo el numero de filas de calificaciones que encuentre
$promedio = $suma/$contador; //AQUI MARCA UN ERRROR: DIVISION BY CERO
$rpromedio = round($promedio,3);
$contador = 0;
$suma = 0;
$pdf->Ln(3);
$pdf->SetX(132);
$pdf->Cell(25,6,'PROMEDIO:',1,0,'C',1);
$pdf->SetX(158);
$pdf->Cell(24,6,$rpromedio,1,0,'C',1);
$pdf->Ln(30);
$pdf->SetX(132);
$pdf->Cell(45,6,'Ing. Alma Rosa Delgado Pineda',1,0,'C',1);
$pdf->Ln(8);
$pdf->SetX(132);
$pdf->Cell(24,6,'Directora',1,0,'C',1);
$pdf->Ln(16);
$pdf->SetX(132);
$pdf->Cell(30,6,$date = date("d-m-Y"),1,0,'C',1);
$pdf->Addpage(); //AGREGANDO PAGINA SIGUIENTE EN CASO QUE EL IDALUMNO NO SEA EL MISMO
//MATRICULA
$pdf->SetX(19);//posisionamos en 10 de x
$pdf->Cell(25,5,$fila['matricula'],1,0,'C',1);
//NOMBRE ALUMNO COLPLETO
$pdf->SetX(47);//posisionamos en 10 de x
$pdf->Cell(100,5,$fila['nombre'],1,0,'C',1);//colocando ancho de celda
//SEMESTRE
$pdf->SetX(150);//posisionamos en 10 de x
$pdf->Cell(9,5,$fila['semestre'],1,0,'C',1);
//PERIODO
$pdf->SetX(161);//posisionamos en 10 de x
$pdf->Cell(24,5,$fila['descripcion'],1,0,'C',1);
//CAPACITACION DONDE ESTA INSCRITO
$pdf->Ln();
$pdf->Ln();
$pdf->SetX(78);//posisionamos en 10 de x
$pdf->Cell(40,5,$fila['capacitacion'],1,0,'C',1);
//NUMERO DE GRUPO
$pdf->SetX(120);//posisionamos en 10 de x
$pdf->Cell(8,5,$fila['grupo'],1,0,'C',1);
$pdf->Ln();
$pdf->Ln();
$pdf->SetX(22);//posisionamos en 10 de x DATOS DE LA PRIMERA HOJA RECUPERADA CON LAS CALIFS DE UN ALUMNO
$pdf->Cell(109,6,'UNIDAD ACADEMICA CURRICULAR',1,0,'C',1);//colocando ancho de celda
$pdf->SetX(132);//posisionamos en 10 de x
$pdf->Cell(25,6,'INASISTENCIAS',1,0,'C',1);//
$pdf->SetX(158);
$pdf->Cell(24,6,'CALIFICACION',1,0,'C',1);
$pdf->Ln();
$pdf->SetX(22);
$pdf->Cell(109,6, $fila['materia'],1,0,'C');
$pdf->SetX(132);//nombre alumno
$pdf->Cell(25,6, $fila['ina1mat'],1,0,'C',0);
$pdf->SetX(158);
$pdf->Cell(24,6, $fila['p1mat'],1,1,'C',0);
//SI LA MATERIA ES PARAESCOLAR O TUTORIA NO SE TOMA EN CUENTA PARA PROMEDIO
if ( ($fila['areaComponente'] == 'Paraescolares') || ($fila['areaComponente'] == 'Tutorias') ) {
$suma = $suma; //suma tendrra el valor anterior
$contador = $contador; //contador tendra el valor anterior
} else {
$valorFila = $fila['p1mat']; //una variable que guardara la calificacion
$suma = $suma + $valorFila; //variable de sumatoria, que agregara el $valorFila
$contador++; //incrementa el contador
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
} //fin else
$bandera = $fila['idAlumno'];
} //fin while (fila = res)
/*$promedio = $suma/$contador;
$rpromedio = round($promedio,3);*/ //AQUI MARCA UN ERRROR: DIVISION BY CERO T FALTA DE VARIABLE $rpromedio
$pdf->Ln(3);
$pdf->SetX(132);
$pdf->Cell(25,6,'PROMEDIO:',1,0,'C',1);
$pdf->SetX(158);
$pdf->Cell(24,6,$rpromedio,1,0,'C',1);
$pdf->Ln(30);
$pdf->SetX(132);
$pdf->Cell(45,6,'Ing. Jesus Sánchez',1,0,'C',1);
$pdf->Ln(8);
$pdf->SetX(132);
$pdf->Cell(24,6,'Director',1,0,'C',1);
$pdf->Ln(16);
$pdf->SetX(132);
$pdf->Cell(30,6,$date = date("d-m-Y"),1,0,'C',1);
$pdf->Output(); //ERROR DE LINEA 276 AL IMPRIMIR FUERA DEL BUCLE LA VARIABLE $rpromedio
?>