<?php
ob_start();
require( 'fpdf.php' );
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Open();
$con = mysqli_connect( "localhost", "root", "", "my_db" );
// Check connection
if ( mysqli_connect_errno() ) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query( $con, "SELECT * FROM Persons" );

while ( $row = mysqli_fetch_array( $result ) ) {
    $fname = $row['FirstName'];
    $lname = $row['LastName'];
    $age   = $row['Age'];
    $pdf->Cell( "{$fname}" );
    $pdf->Cell( "{$lname}" );
    $pdf->Cell( "{$age}" );
}
$pdf->Output();
?>

Recommended Answers

All 3 Replies

You did not mention what is the exact problem you are facing.

Since you used ob_start, wouldn't you have to use ob_flush to get some output?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.