PHP Example
Screen shot
Export Mysql data to MSExcel

<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<title>Export data from Mysql to MSExcel</title>
</head>
<body>
<a href=\"download.php\">Export</a>
</body>
</html>

download.php
<?php

// Mysql connectivity and database connectivity
$conn=mysql_connect(\'localhost\',\'root\',\'\') or die(\'Mysql not connected\');
$database=mysql_select_db(\'test\',$conn) or die(\'Database Not connected\');

$file = \'export\';

//Mysql query to get records from database
$query=\"SELECT * FROM multiple_record\";
$result=mysql_query($query);

//Fetch Records from Database and generate CSV File
$csv_output=\'\';
while($row=mysql_fetch_array($result))
{
$csv_output .= $row[\'id\'].\",\".$row[\'username\'].\",\".$row[\'email_id\'].\",\".$row[\'city\'];
$csv_output .= \"\\n\";
}
$filename = \'export\'.time();
header(\"Content-type: application/vnd.ms-excel\");
header(\"Content-disposition: csv\" . date(\"Y-m-d\") . \".csv\");
header(\"Content-disposition: filename=\".$filename.\".csv\");
print $csv_output;
exit;

?>

Database
-- Database: `test`

-- Table structure for table `multiple_record`

CREATE TABLE IF NOT EXISTS `multiple_record` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `email_id` varchar(255) NOT NULL,
  `city` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

-- Dumping data for table `multiple_record`

INSERT INTO `multiple_record` (`id`, `username`, `email_id`, `city`) VALUES
(1, \'john\', \'john120@gmail.com\', \'America\'),
(2, \'Harry\', \'harry.cool@facebook.com\', \'USA\'),
(3, \'michel\', \'michel.mikky@yahoo.uk\', \'UK\'),
(4, \'petrick\', \'petrick.9087@yahoo.usa\', \'USA\'),
(5, \'jolly\', \'jolly.jack@gmail.com\', \'Canada\');


You can download source code here