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

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

sabung ayam online

THOR311

parlay

RATU311

KUPU178

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

CERI188

CERI188

KUPU178

RATU311: Alternatif karnpuracollege

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

RATU311

RATU311

RATU311

judi bola

live casino

sv388

sv388

sabung ayam online

sabung ayam online

Thor311 Terbaru

CERI188: Taruhan Bola Sbobet

THOR311 DEMO SLOT

THOR311 MAHJONG

RATU311: BONUS SABUNG AYAM

CERI188

parlay

KUPU178

RATU311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

CERI188

CERI188: Masuk Akun Slot Super Cepat

KUPU178: Slot Online Mahjong Bet 200

THOR311 PRO

THOR311

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

CERI188

THOR311

HOKI311

HOKI311

RATU311

RATU311

KUPU178

THOR311

KUPU178

THOR311

RATU311

HOKI311

KUPU178

KUPU178

RATU311

THOR311 TOTO4D

KUPU178

Live Casino Roullate

RATU311

RATU311

RATU311

RATU311

THOR311

THOR311

THOR311

RATU311

CERI188

DAFTAR KUPU178

LINK DAFTAR CERI188

CERI188

APK KUPU178

KUPU178

CERI188

CERI188

RATU311

KUPU178

THOR311 DOMINO QQ

judi bola online

Mix Parlay

CERI188

CERI188

CERI188

RATU311

live casino online

RATU311

Mix Parlay

Sabung Ayam Online

Slot PG Soft

CERI188

RATU311

RATU311

CERI188

THOR311

CERI188

THOR311

Game Thor311

THOR311

HOKI311

live casino

sv388

HOKI311

HOKI311

slot mahjong

Thor311 Alternatif

RATU311

HOKI311

HOKI311

HOKI311

HOKI311

CERI188

THOR311 RESMI

THOR311 AKSES

THOR311

THOR311 RTP

parlay

HOKI311

THOR311

Thor311 Aplikasi

RATU311 NONTON BOLA

CERI188 Link RTP LIVE

THOR311

Thor311 Live Casino

CERI188

akses VIP THOR311

THOR311

link daftar THOR311

THOR311

situs thor311

RATU311

HOKI311 Link SABUNG AYAM RESMI

HOKI311 Link QRIS EWALLET

RATU311

LINK CERI188

parlay

HOKI311 Link RTP Gacor

THOR311

HOKI311 Link Apk Resmi

CERI188

KUPU178 Link Daftar

CERI188

CERI188

CERI188

CERI188

CERI188

HOKI311

RATU311

RATU311

HOKI311 Lapak Arena Slot

RATU311 judi bola

HOKI311 Link Spaceman Online

HOKI311 Link Daftar Resmi

CERI188 Toto SGP Online

KUPU178

HOKI311 TEMBAK IKAN ONLINE

KUPU178

HOKI311 Link Login Alternatif

HOKI311 Live Casino Online

HOKI311 Situs Slot Gacor

THOR311

THOR311

situs judi bola

Ceri188 Game Online

CERI188

link login CERI188

link login CERI188

CERI188

THOR311

HOKI311

HOKI311

CERI188

parlay

THOR311

RATU311

HOKI311

HOKI311

HOKI311

RATU311

THOR311

KUPU178

HOKI311

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

KUPU178

KUPU178

THOR311

KUPU178

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

KUPU178

KUPU178

HOKI311

THOR311

KUPU178

THOR311

THOR311

slot thailand

judi bola

THOR311

THOR311

KUPU178

THOR311

THOR311

slot gacor

slot gacor

yakuza303

unobet77

slot gacor

slot gacor

RATU311

parlay

parlay

slot gacor

parlay

THOR311