Eksport Data Table Mysql ke Excel dengan PHP

script php untuk eksport data table mysql ke Excel

<?php
$konek=mysql_connect(‘localhost’,'user’,'password’) or die (mysql_error());
$db=mysql_select_db(‘database’) or die (mysql_error());

$filename=”test.xls”;
$qry=mysql_query(“select * from user order by id_user asc”);

// generate kolom
$header = “ID user \t userame \t password \t \n”;

// generate baris
while($row = mysql_fetch_array($qry)) {
for($x=0; $x<3; $x++) {
$content .= $row[$x].” \t “;
}
$content .= ” \n “;
}
$output = $header.$content;

header(‘Content-type: application/ms-excel’);
header(‘Content-Disposition: attachment; filename=’.$filename);

echo $output;
?>

Sumber :

http://freshanella.wordpress.com/2010/06/02/cara-export-data-mysql-ke-excel-dengan-php/

Leave a Reply

*


× six = 18