if( mysql_connect("localhost","user","password") ){
mysql_select_db("kepegawaian");
}
$title = "Exporting Sederhana dari SQL ke XLS";
$content_header = "<table><tr><th>NIP</th><th>Nama</th><th>Jumlah Honor</th><th>Status Terima</th></tr>";
$content_footer = "</table>";
$content_dalam = "";
$sql = "SELECT * FROM `pegawai`";
$q = mysql_query( $sql );
while( $r=mysql_fetch_array( $q ) ){
$data = "<tr><td>".$r['nip']."</td><td>".$r['nama']."</td><td>".$r['honor']."</td><td>".$r['status_ambil']."</td></tr>";
$content_dalam = $content_dalam ."\n". $data;
}
$content_sheet = $title . "\n" . $content_header . "\n" . $content_dalam . "\n" . $content_footer;
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=excel.xls");
header("Pragma: no-cache");
header("Expires: 0");
print $content_sheet;
No comments:
Post a Comment