I am trying to print records of a table into a pdf file using fpdf, to this I am using for each loop, but it just prints one record though it works fine without fpdf class. here is the code:
if(isset($_GET['show_id'])){
$id = ($_GET['show_id']);
$comments = selectAll('proposal_comment', ['proposal_id' => $id]);
foreach($comments as $comment){
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(100,10,$comment['message']);
$pdf->Output();
}
}
any idea why is it like this?
Move the initialisation code outside the loop and then the loop will just add cells
if(isset($_GET['show_id'])){
$id = ($_GET['show_id']);
$comments = selectAll('proposal_comment', ['proposal_id' => $id]);
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
foreach($comments as $comment){
$pdf->Cell(100,10,$comment['message']);
}
$pdf->Output();
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments