I want to display the result of a SQL QUERY wich can have variable columns number, lines number in a PDF file that will have the right number of columns. And will display the content of each cell using the Multicell function to display all my text in multiple line in each cell.
$query = mysqli_query($this->connect,$sql);
$field = mysqli_num_fields($query);
$pdf = new PDF();
//header
$pdf->AddPage();
//foter page
$pdf->AliasNbPages();
$pdf->SetFont('Arial','B',5);
$header =[];
for($i = 0; $i < $field; $i++) {
array_push($header, mysqli_field_name($query,$i));
}
foreach($header as $heading) {
$pdf->Cell(25,10,$heading,1);
}
$x = $pdf->GetX();
$y = $pdf->GetY();
$push_down = 0;
foreach($query as $columns){
$pdf->Ln();
$push_right = 0;
foreach($columns as $line){
$pdf->MultiCell(25,10,$line, 'LRT', 'J', 0);
$push_right += 25;
$pdf->SetXY($x + $push_right, $y);
}
$push_down += 10;
$pdf->SetXY($x , $y + $push_down);
}
$pdf->Output();
I can't find a way to properly use x, y. I think I'm messing something obvious, but I'm struggling to find what.