-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvA22.20.php
38 lines (29 loc) · 1.4 KB
/
csvA22.20.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
<?php
//include database configuration file
include 'configA222.php';
//get records from database
$query = $connection->query("SELECT * FROM a2220 ORDER BY Date_of_Application DESC");
if($query->num_rows > 0){
$delimiter = ",";
$filename = "MLIREC_2020_RECORDS" . date('Y-m-d') . ".csv";
//create a file pointer
$f = fopen('php://memory', 'w');
//set column headers
$fields = array('Name_of_Applicant', 'Date_of_Application',' Section_to_be_Varied', 'Cat_of_affected_employees', 'Recommendations', 'Variation_end_date', 'filename' );
fputcsv($f, $fields, $delimiter);
//output each row of the data, format line as csv and write to file pointer
while($row = $query->fetch_assoc()){
$Variation_end_date = ($row['Variation_end_date'] == '1')?'':'';
$lineData = array($row['Name_of_Applicant'], $row['Date_of_Application'], $row['Section_to_be_Varied'], $row['Cat_of_affected_employees'], $row['Recommendations'],$row['Variation_end_date'],$row['filename']);
fputcsv($f, $lineData, $delimiter);
}
//move back to beginning of file
fseek($f, 0);
//set headers to download file rather than displayed
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
//output all remaining data on a file pointer
fpassthru($f);
}
exit;
?>