How to Generate HTML table data to PDF from MYSQL database in PHP

generate html table data to pdf from mysql database using tcpdf in php

How to Generate HTML table data to PDF from MYSQL database in PHP

Hi, friends in this post I will show you how to generate HTML table data to PDF from MySQL database using in PHP. The TCPDF library is best for generating pdf file from HTML data in PHP. Many of the developers using this library for generating the pdf file in their projects. The official site of TCPDF library and here you can view that it is presently one of the world’s complete live Open Source projects used every day by most of the users and incorporated in Content Management system (CMS) also.

generate html table data to pdf from mysql database using tcpdf in php

How to Generate HTML table data to PDF from MYSQL database in PHP

Database Connection file : config.php


<?php 
error_reporting(0); 
$mysqli=new mysqli("localhost","root","","jollofblog"); // database connection code ?>

Index.php file for the html and Ajax code

<?php 
include "config.php";
?>
<html>
<head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>

<body>
<div align="center">
 <a href="pdfGenerator.php" class="btn btn-info" role="button">Generate PDF</a>
</div>

<div class="container">

 <table class="table">
 <thead>
 <tr>
 
 
 <th>ID</th>
 <th>Name</th>
 <th>Country</th>
 <th>City</th>
 <th>Loan Amount</th>
 </tr> 
 </thead>
 <?php
 $c=0; // initialize a counter for serial number her
$sql1=mysqli_query($mysqli,"SELECT * FROM ajax_php_jquery_live_search A WHERE A.status='1'"); // sql statement to fetch record based on the status picked
 while($row = mysqli_fetch_array($sql1))
 {
 $c++;
 extract($row);
?>
 <tbody>
 
 
 <tr>
 
 <td><?php echo $c;?></td>
 <td><?php echo $name;?></td>
 <td><?php echo $country;?></td>
 <td><?php echo $city;?></td>
 <td><?php echo number_format($amount,2);?></td>
 </tr>
 </tbody>
 <?php } ?>
 </table>
</div>
</body>

</html>

 

How to Generate HTML table data to PDF from MYSQL database in PHP How to fetch data from database without submitting HTML form Retrieving Data with jQuery AJAX Without Reloading Page