-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvA222.16.php
38 lines (29 loc) · 1.46 KB
/
csvA222.16.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 a22216 ORDER BY Date_Received DESC");
if($query->num_rows > 0){
$delimiter = ",";
$filename = "MLIREC_2016_RECORDS" . date('Y-m-d') . ".csv";
//create a file pointer
$f = fopen('php://memory', 'w');
//set column headers
$fields = array('Name_of_Applicant', 'Date_Received','Positions', 'Number_of_Positions', 'No_of_Positions_Recommended', 'No_of_Positions_not_Recommended','Remarks','Exemption_end_date');
fputcsv($f, $fields, $delimiter);
//output each row of the data, format line as csv and write to file pointer
while($row = $query->fetch_assoc()){
$Exemption_end_date = ($row['Exemption_end_date'] == '1')?'':'';
$lineData = array($row['Name_of_Applicant'], $row['Date_Received'], $row['Positions'], $row['Number_of_Positions'], $row['No_of_Positions_Recommended'],$row['No_of_Positions_not_Recommended'],$row['Remarks'],$row['Exemption_end_date'], $Exemption_end_date);
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;
?>