-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.php
50 lines (40 loc) · 1.27 KB
/
export.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
43
44
45
46
47
48
49
50
<?php
/*
* @author Shahrukh Khan
* @website http://www.thesoftwareguy.in
* @facebbok https://www.facebook.com/Thesoftwareguy7
* @twitter https://twitter.com/thesoftwareguy7
* @googleplus https://plus.google.com/+thesoftwareguyIn
*/
require_once("configure.php");
$filename = "testing-exports.csv";
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
$sql = "SELECT * FROM tbl_products1 WHERE 1";
try {
$stmt = $DB->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll();
} catch (Exception $ex) {
printErrorMessage($ex->getMessage());
}
$content = array();
$title = array("Name", "Quantity", "Model", "Price", "Weight", "Status");
foreach ($results as $rs) {
$row = array();
$row[] = stripslashes($rs["products_name"]);
$row[] = stripslashes($rs["products_quantity"]);
$row[] = stripslashes($rs["products_model"]);
$row[] = stripslashes($rs["products_price"]);
$row[] = stripslashes($rs["products_weight"]);
$row[] = ($rs["products_status"] == "A") ? "Active" : "Inactive";
$content[] = $row;
}
$output = fopen('php://output', 'w');
fputcsv($output, $title);
foreach ($content as $con) {
fputcsv($output, $con);
}
?>