-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_excel.php
42 lines (38 loc) · 1.05 KB
/
generate_excel.php
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
34
35
36
37
38
39
40
41
42
<?php include 'db.php'; ?>
<?php
$query = "SELECT * FROM customer_data";
$results = mysqli_query($conn, $query);
$tasks = array();
while( $rows = mysqli_fetch_assoc($results) ) {
$tasks[] = $rows;
}
if(isset($_POST["ExportType"]))
{
switch($_POST["ExportType"])
{
case "Download to excel" :
// Submission from
$filename = "list_of_customers".date('Ymd') . ".xls";
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"$filename\"");
ExportFile($tasks);
//$_POST["ExportType"] = '';
exit();
default :
die("Unknown action : ".$_POST["action"]);
break;
}
}
function ExportFile($records) {
$heading = false;
if(!empty($records))
foreach($records as $row) {
if(!$heading) {
// display field/column names as a first row
echo implode("\t", array_keys($row)) . "\n";
$heading = true;
}
echo implode("\t", array_values($row)) . "\n";
}
exit;
}