Report php and Mysql with records of the same client

2

Good evening I hope and you can help me I have a query in mysql that displays the data in the following way

but I need the records to be this way

I'm doing the report with fpdf I have the following

$sql1 ="select a.estudiante_Carnet, b.PrimerNombre, b.PrimerApellido, a.Nota1
from notas a
inner join estudiante b
on a.estudiante_Carnet = b.Carnet
where b.grado_CodigoGrado='b3b'";

$res = mysqli_query($conexion,$sql1);
$row = mysqli_fetch_array($res);
$bandera = $row['b.Carnet'];


$pdf = new PDF();
//$pdf = new FPDF('P','mm',array(165,220));

$pdf->Addpage();
$pdf->AliasNbPages();


$pdf->SetFont('Arial','B',5);
    $pdf->Ln(10);

   $res2 = mysqli_query($conexion,$sql1);




    $pdf->Cell(10,10, "hola",1,1,'C',0);


while ($fila = $res2->fetch_array())  
{   

    if ( $bandera ==  $fila['b.Carnet'] ) {





    $bandera = $fila['b.Carnet'];

$pdf->Cell(10,10, $fila['PrimerNombre'],1,0,'C',0);         
   $pdf->Cell(10,10, $fila['Nota1'],1,0,'C',0);   
      $pdf->Ln();

  } 

  else { 

     ////////////////////////////////////////////////////////////////////   
    $pdf->Addpage();  


    $bandera = $fila['b.Carnet'];
      $pdf->Cell(10,10, $fila['PrimerNombre'],1,0,'C',0);  
   $pdf->Cell(10,10, $fila['Nota1'],1,0,'C',0);   
      $pdf->Ln();


}   
}

$pdf->Output();

?>
    
asked by Carlos Josue Tirado Garcia 30.07.2018 в 06:27
source

1 answer

0

This way of grouping or structuring the information is called Pivot there are databases like SQLServer for example that bring the function incorporated by default however others like MySQL have only the practice and the habit of doing it, they are called to these tables as Tabla Pivot . That is, you have to do 'botched' or other adjustments to get the result.

From my own experience I would recommend that you treat the information in your programming language directly to structure it in this way since it will be done more quickly with large amounts of data.
The effect is as follows:

  • Normal search:
  • Search with pivot structure:
  

I'm not sure how your tables are structured, but to get the result you need the number of notes has to be fixed, that is; it is not possible to generate infinite columns of Nota1,Nota2...hasta el infinito notes in this format at least, edit your answer and add the structure of the tables and if possible what will be the maximum number of notes per student. And if above all in the table has a Note1, Note2 etc much better.   My recommendation would be that in the 'notes' table you add a column with the note number, that is%% of%

    
answered by 30.07.2018 в 09:27