'How to I get FPDF cells to word wrap, but also align next to each other, rather than stack on top of each other?
I am a student attempting to complete a PHP assignment, but I have one last thing I cannot figure out. I am required to create a PDF (using a PHP file) that pulls data from a MySQL database and displays that data in a nicely-formatted table. The issue is when I display the data using MultiCell(), each cell is stacked on top of each other, rather than being aligned horizontally. However, if I use Cell(), the columns do not wrap and extend off the page. Below is my code:
$result = mysqli_query($con, $sql);
$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->SetFillColor(200,105,77);
$pdf->Write(10,'This is a PDF created with the FPDF library, PHP, and MySQLi.
The following table is comprised of information about some of my
favorite literary authors, which was pulled from a MySQL database. ');
$pdf->SetFont('Arial', 'B', 8);
$pdf->MultiCell(35,10,'Author ID',1,0,'C',true);
$pdf->MultiCell(35,10,'First Name',1,0,'C',true);
$pdf->MultiCell(35,10,'Last Name',1,0,'C',true);
$pdf->MultiCell(35,10,'Age',1,0,'C',true);
$pdf->MultiCell(35,10,'Home City',1,0,'C',true);
$pdf->SetFillColor(17, 222, 91);
$fill=false;
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$pdf->MultiCell(35,10,$row['author_id'],1,0,'C',$fill);
$pdf->MultiCell(35,10,$row['first_name'],1,0,'C',$fill);
$pdf->MultiCell(35,10,$row['last_name'],1,0,'C',$fill);
$pdf->MultiCell(35,10,$row['age'],1,0,'C',$fill);
$pdf->MultiCell(35,10,$row['home_city'],1,0,'C',$fill);
$fill = !$fill;
}
}
$pdf->Output();
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
