In the context of generating a PDF with PHP, what are some best practices for handling and displaying data fetched from a database query within the code snippet provided?

When handling and displaying data fetched from a database query in a PDF generated with PHP, it is important to properly format and structure the data to ensure readability and consistency. One best practice is to loop through the query results and format the data accordingly before adding it to the PDF document. Additionally, consider using HTML or CSS styling to enhance the presentation of the data within the PDF.

// Assume $queryResult contains the fetched data from a database query

// Create a new PDF document
$pdf = new FPDF();
$pdf->AddPage();

// Loop through the query results and add data to the PDF document
foreach ($queryResult as $row) {
    $pdf->Cell(0, 10, $row['column1'] . ' - ' . $row['column2'], 0, 1);
}

// Output the PDF document
$pdf->Output();