-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.php
More file actions
29 lines (23 loc) · 1.02 KB
/
export.php
File metadata and controls
29 lines (23 loc) · 1.02 KB
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
<?php
function array_to_csv_download($array, $filename = "export.csv", $delimiter = ";")
{
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
// open the "output" stream
// see http://www.php.net/manual/en/wrappers.php.php#refsect2-wrappers.php-unknown-unknown-unknown-descriptioq
$f = fopen('php://output', 'w');
foreach ($array as $line) {
fputcsv($f, $line, $delimiter);
}
}
if (isset($_POST["Export"]) && $_SERVER['REQUEST_METHOD'] === 'POST') {
include('configTrumbullIndustries.php');
$sql = "SELECT * FROM `sample-data`";
$result = mysqli_query($conn, $sql);
$data = array();
$data[] = array('ID', 'SKU', 'TSI', 'VENDOR', 'BRAND', 'SHIPPING TEMPLATE', 'TEMPLATE CODE', 'INSTOCK LEADTIME', 'NOSTOCK LEADTIME', 'QUANTITY', 'OBSOLETE', 'IS UPDATED');
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
array_to_csv_download($data, "export.csv", ",");
}