The goal I am trying to achieve is to run a mysql query, place the output into a foreach and then dump all the results into a pdf document using the awesome FPDF library. However only the last result record is making it into the pdf library. Here is mysql query:
$sql1 = "SELECT
mytable.AddressLine1,
mytable.OrgID
FROM
mytable";
$results = $db->query($sql1);
Here is my PHP:
foreach ($results as $all_data) {
$border = 0;
$cardWidth = 1;
$cardHeight = 1;
require_once('fpdf/fpdf.php');
require_once('fpdf/fpdi.php');
$pdf = new FPDI('P','in','Letter');
$pdf->setSourceFile(realpath(ROOT_DIR . 'view' . URL_PATH . 'snTemplate.pdf'));
$pdf->AddPage();
$template = $pdf->importPage(1);
$pdf->useTemplate($template);
$pageNumber = 1;
$pdf->SetFont('Arial', '', 6);
$pdf->SetXY(0, 9.8);
$pdf->MultiCell(8.5, .2, 'Page ' . $pageNumber, $border,'C');
$pdf->SetXY(0, 9.9);
$pdf->MultiCell(8.5, .2,' Report Form ', $border, 'C');
$pdf->SetXY(0, 10);
$pdf->MultiCell(8.5, .2,
$all_data['AddressLine1'] . ' - ' . $all_data['OrgID'], $border, 'C');
$pdf->Output('Name' . 'sanctionReport' . '.pdf','I');
}
Again there are four results in the table, but only the last recordset is output into the PDF, I would like all results to appear on their individual page, all with in the same report, really dont want to have multiple download boxes on the users screen... they tend to get frightened!