<?php
// The function header by sending raw excel
header("Content-type: application/vnd-ms-excel");
 
// Defines the name of the export file "codelution-export.xls"
header("Content-Disposition: attachment; filename=data-transaksi.xls");
 
// Add data table
?>
<table border="1">
    <tr>
    	<th>NO.</th>
		<th>NAME</th>
		<th>Major</th>
	</tr>
	<?php
	//connection to mysql
	mysql_connect("localhost", "root", ""); //server , username , password
	mysql_select_db("mhs");
	
	//query get data
	$sql = mysql_query("SELECT * FROM tbpejabat");
	$no = 1;
	while($data = mysql_fetch_assoc($sql)){
		echo '
		<tr>
			<td>'.$no.'</td>
			<td>'.$data['nama'].'</td>
			<td>'.$data['NIP'].'</td>
		</tr>
		';
		$no++;
	}
	?>
</table>