forked from Bhanu-183/Coinage-Crew
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_export.php
More file actions
32 lines (26 loc) · 990 Bytes
/
csv_export.php
File metadata and controls
32 lines (26 loc) · 990 Bytes
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
<?php
include('db_conn.php');
$grp_id=$_GET['grp_id'];
$query = $conn->query("SELECT * FROM `members`,`users` WHERE grp='$grp_id' AND user_id=id");
if($query->num_rows > 0){
$delimiter = ",";
$filename = "members-data_" . date('Y-m-d') . ".csv";
// Create a file pointer
$f = fopen('php://memory', 'w');
$fields = array('Group Name','NAME','Group _ID','STATUS');
fputcsv($f, $fields, $delimiter);
$res2=$conn->query("SELECT * FROM `groups` WHERE grp_id='$grp_id'");
$row2=$res2->fetch_assoc();
$grp_name=$row2['grp_name'];
while($row = $query->fetch_assoc()){
$status = ($row['paid'] == 1)?'Paid':'Unpaid';
$lineData = array($grp_name,$row['name'], $row['grp'], $status);
fputcsv($f, $lineData, $delimiter);
}
fseek($f, 0);
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
fpassthru($f);
}
exit;
?>