I've a table whose data is brought and printed on the PDF report. The problem is that Trainee Name column's text is inserting with attached cell (Training Title).
I've gone through Link 1, Link 2, Link 3 but couldn't understand what to do?
Here is my PHP Code:
<?php
require('fpdf/fpdf.php'); // Adjust the path based on your project structure
include "my-connection.php";
// Fetch data from the "items" table
$query = "SELECT
tp.participant_id ID,
tree.name Trainee,
trpr.training_title,
tp.training_date,
tp.is_attended,
tp.remarks
FROM
training_participants tp
LEFT JOIN trainees tree ON
tree.trainee_id = tp.trainee_id
LEFT JOIN training_profiles trpr ON
trpr.training_profile_id = tp.training_profile_id
LEFT JOIN trainers trs ON
trs.trainer_id = tp.trainer_id
LEFT JOIN training_focal_person trfpo ON
trfpo.focal_person_id = tp.focal_person_id
WHERE
tp.is_deleted = 'true'
ORDER BY
tp.participant_id
DESC";
$result = mysqli_query($myConn, $query);
// Create PDF
$pdf = new FPDF();
$pdf->AddPage();
// Add Heading on the Report
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(0, 10, 'Items List', 0, 1, 'C'); // 'C' stands for center alignment
$pdf->Ln(10); // Add some space after the heading
$pdf->SetFont('Arial', '', 16);
// Set column names
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(10, 10, 'ID', 1);
$pdf->Cell(40, 10, 'Trainee', 1);
$pdf->Cell(80, 10, 'Title', 1);
$pdf->Cell(25, 10, 'Date', 1);
$pdf->Cell(10, 10, 'Att', 1);
$pdf->Cell(20, 10, 'Remarks', 1);
$pdf->Ln(); // Move to the next line
// Set data from database
$pdf->SetFont('Arial', '', 12);
while ($row = mysqli_fetch_assoc($result)) {
$pdf->Cell(10, 10, $row['ID'], 1);
$pdf->Cell(40, 10, $row['Trainee'], 1);
//$pdf->MultiCell(40, 10, $row['Trainee'], 1);
$pdf->Cell(80, 10, $row['training_title'], 1);
$pdf->Cell(25, 10, $row['training_date'], 1);
$pdf->Cell(10, 10, $row['is_attended'], 1);
$pdf->Cell(20, 10, $row['remarks'], 1);
$pdf->Ln(); // Move to the next line
}
// Output PDF
$pdf->Output();
// Close database connection
mysqli_close($myConn);
?>
In the visited URLs, I've seen one thing to use
$pdf->MultiCell
But even by using it, the line is broken after the cell and all the alignment gets mixed up.
Please guide me that how to make it happen?
Thank you.