How to export MySQL table data into excel using jQuery


How to export MySQL table data into excel using jQuery

Hi friends, in this tutorial we will learn how to export MySQL table data into excel using jQuery plugin. On the other hand, it can also be done with the help of PHP script. We will discuss it in the upcoming tutorial. But for now, in order to export table data successfully, we have to follow the below steps one by one.

  1. Download the jQuery Plugin to export the table data.
    You can also download the plugin from here.
  2. Just make a folder and extract the plugin archive and place the archive folder where you have created your PHP file in the root directory.
  3. Fetch the MySQL table data from the database in the HTML page with the help of the PHP script.

DDL information of the table

CREATE TABLE student (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
student_name varchar(225) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
phone_no varchar(225) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
age int(20) DEFAULT NULL,
date_of_birth date DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

<?php
include('connect.php');
//get the student information from the student table in the database
$stmt = $con->prepare("select * from student");
$stmt->execute();
$student_details = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

4. Include the source file “table2excel.js” in the script tag as shown below.


<script src="jquery-table2excel-master/src/jquery.table2excel.js"></script>

5. Write the function in the script tag of the HTML page to call the plugin for exporting the table data in the excel format.

<script src="jquery-3.2.1.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="jquery-table2excel-master/src/jquery.table2excel.js"></script>
<script>
//export to excel
$(".export").click(function(){
  $("#mytable").table2excel({
    // exclude CSS class
    exclude: ".noExl",
    name: "Data",
    filename: "report", //do not include extension
    fileext: ".xls" // file extension
  }); 
});
</script>

Complete Code:-

<?php
include('connect.php');
//get the student information from the student table in the database
$stmt = $con->prepare("select * from student");
$stmt->execute();
$student_details = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<html>
<head>
<title>ajax example</title>
<link rel="stylesheet" href="bootstrap.css" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="bootstrap-theme.css" crossorigin="anonymous">
<style>
.container{
	width:50%;
	height:30%;
	padding:20px;
}
</style>
</head>

<body>
	<div class="container">
	<h3><u>Export MySql Table Data into Excel Using jQuery</u></h3>
	<br>
	<p><b>Student Information:</b></p>
	<br/>     
	  <table class="table table-bordered" id="mytable">
	    <thead>
	      <tr>
	      	<th>Sl No</th>
	        <th>Student Name</th>
	        <th>Phone No</th>
	        <th>Age</th>
	        <th>Date of Birth</th>
	      </tr>
	    </thead>
	    <tbody>
	<?php
	foreach($student_details as $key=>$value)
	{
		echo '<tr>
			<td>'.($key+1).'</td>
		        <td>'.$value['student_name'].'</td>
		        <td>'.$value['phone_no'].'</td>
		        <td>'.$value['age'].'</td>
		        <td>'.$value['date_of_birth'].'</td>
		      </tr>';
	}
	?>

	    </tbody>
	  </table>
	  <button type="button" class="btn btn-success btn-sm export">Export to Excel</button>
    </div>
<script src="jquery-3.2.1.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="jquery-table2excel-master/src/jquery.table2excel.js"></script>
<script>
//export to excel
$(".export").click(function(){
  $("#mytable").table2excel({
    // exclude CSS class
    exclude: ".noExl",
    name: "Data",
    filename: "report", //do not include extension
    fileext: ".xls" // file extension
  }); 
});
</script>
</body>
</html>

NOTE*

Download the bootstrap CSS and js files from google and include the path of the files in the href attribute of link tag and src attribute of the script tag respectively.

Also Read, Create Multi-step form submission in PHP using jQuery

CONCLUSION:- I hope this tutorial will help you. If you have any doubt on how to export mysql table data into excel using jQuery, then please leave your comment below


Leave a Comment

CERI188

HOKI311

RATU311

RATU311

judi bola online

Mix Parlay

THOR311

Ceri188

Thor311 Game Online

Thor311 Aplikasi

LINK CERI188

RATU311 NONTON BOLA

RATU311

HOKI311 Link Alternatif

CERI188 Link RTP LIVE

THOR311

THOR311

Thor311 Live Casino

CERI188

akses VIP THOR311

THOR311

link daftar THOR311

THOR311

situs thor311

THOR311 LOGIN

THOR311

THOR311

THOR311

RATU311

RATU311

HOKI311 Link SABUNG AYAM RESMI

HOKI311 Link QRIS EWALLET

RATU311

LINK CERI188

parlay

HOKI311 Link RTP Gacor

THOR311

RATU311

THOR311

THOR311

HOKI311 Link Apk Resmi

RATU311

KUPU178

RATU311

RATU311

RATU311

CERI188

CERI188 Situs Spaceman Terbaik 2026

KUPU178 Link Daftar

CERI188

CERI188

CERI188

CERI188

CERI188

HOKI311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

CERI188 Live Casino

HOKI311 Lapak Arena Slot

RATU311 judi bola

CERI188 Live Casino

HOKI311 Link Spaceman Online

RATU311

HOKI311 Link Daftar Resmi

CERI188 Toto SGP Online

KUPU178

KUPU178

KUPU178

KUPU178

HOKI311 TEMBAK IKAN ONLINE

RATU311

CERI188 PANDUAN MAXWIN SLOT ONLINE

RATU311

RATU311

RATU311

KUPU178

HOKI311 Link Login Alternatif

HOKI311 Live Casino Online

HOKI311 Situs Slot Gacor

THOR311

THOR311

situs judi bola

THOR311

Ceri188 Game Online

CERI188

link login CERI188

THOR311

link login CERI188

CERI188

link login CERI188

link login CERI188

link daftar CERI188

THOR311

HOKI311

HOKI311

CERI188

CERI188

CERI188

parlay

THOR311

RATU311

RATU311

HOKI311

HOKI311

parlay

HOKI311

RATU311

THOR311

KUPU178

HOKI311

KUPU178

KUPU178

KUPU178

HOKI311

parlay

slot gacor

kupu178 link alternatif

kupu178 slot

kupu178 daftar

kupu178 login

link daftar kupu178

judi bola

HOKI311

RATU311

link alternatif RATU311

Link daftar RATU311

link login RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

KUPU178

THOR311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

RATU311

KUPU178

KUPU178

HOKI311

THOR311

KUPU178

THOR311

THOR311

slot thailand

judi bola

THOR311

THOR311

KUPU178

THOR311

situs bola

THOR311

slot gacor

slot gacor

yakuza303

slot gacor

unobet77

slot gacor

slot gacor

RATU311

parlay

parlay

slot gacor

mix parlay

judi bola

judi bola

mix parlay

parlay

judi bola

sv388

judi bola

judi bola

judi bola

parlay

THOR311