<?php
// Connection
$conn=mysql_connect('localhost','root','');
$db=mysql_select_db('excel',$conn);
$filename = "fileName.xls"; // File Name
// Download file
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$user_query = mysql_query('select name,work from info');
// Write data to file
$flag = false;
while ($row = mysql_fetch_assoc($user_query)) {
if (!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\r\n";
$flag = true;
}
echo implode("\t", array_values($row)) . "\r\n";
}
?>
Do feel free to ask any questions that you may have concerns to web. No Compromise on Learning!
Wednesday, November 4, 2015
Export MySQL data to Excel in PHP
Subscribe to:
Post Comments (Atom)
How to backup and download Database using PHP
< ?php $mysqlUserName = 'databaseusername' ; $mysqlPassword = 'databasepassword' ; $mysqlHostNa...
-
Welcome to the next part of OpenLayers 3 for Beginners! If you have not worked through parts one or two yet, you can hop over to them he...
-
What is PHPSpreadSheet Library PHPSpreadSheet library is purely writter in PHP and it main purpose of communicate your PHP application with ...
-
Welcome to OpenLayers 3 for Beginners: Part 2. If you have not been to and completed OpenLayers 3 Part 1 yet, head over to http://chris...
No comments:
Post a Comment
Please Comment Here!