-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathexport.php
More file actions
33 lines (29 loc) · 973 Bytes
/
export.php
File metadata and controls
33 lines (29 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
//Header setting to export text data into excel.
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=DATA_EXPORT.xls");
include "config/connect.php";
//Write your SQL here
$sql = mysql_query("SELECT nama, email, hp FROM t_member ORDER BY id");
//This part generate your SQL result into table
echo "<table border='1'>\n";
$cols = mysql_num_fields($sql);
$ncols = $cols - 1;
echo "<tr>\n";
for ($i = 0; $i <= $ncols; ++$i) {
$colname = mysql_field_name($sql, $i);
echo " <th><b>".htmlentities($colname, ENT_QUOTES)."</b></th>\n";
}
echo "</tr>\n";
while (($row = mysql_fetch_array($sql, MYSQL_ASSOC)) != false) {
echo "<tr>\n";
foreach ($row as $therow) {
echo " <td>".(htmlentities($therow, ENT_QUOTES))."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>