-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_file.php
49 lines (31 loc) · 1.3 KB
/
export_file.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
<?php
include("connect.php");
doDB();
$nota =0;
$delimiter = ",";
$filename = $_GET['quiz_id'] ."_". date('Y-m-d') . ".csv";
$f = fopen('php://memory', 'w');
$fields = array('Students_ID', 'No of times attempted', 'Marks');
fputcsv($f, $fields, $delimiter);
$students_sql = "SELECT distinct id FROM marks where quiz_id = '".$_GET['quiz_id']."'";
$students = mysqli_query($con, $students_sql) or die(mysqli_error($con));
while ($marks = mysqli_fetch_array($students)) {
$stud_id = $marks["id"];
$attempt = "SELECT count(*) as nota from marks where quiz_id = '".$_GET['quiz_id']."' and id='".$stud_id."'";
$attempt_res = mysqli_query($con, $attempt) or die(mysqli_error($con));
while ($no = mysqli_fetch_array($attempt_res)) {
$nota = $no["nota"];
}
$marks_sql = "SELECT MAX(marks) as hmarks FROM marks WHERE id = '".$stud_id."' and quiz_id='".$_GET['quiz_id']."'";
$attempt_res = mysqli_query($con, $marks_sql) or die(mysqli_error($con));
while ($hm = mysqli_fetch_array($attempt_res)) {
$marks = $hm["hmarks"];
}
$lineData = array($stud_id, $nota, $marks);
fputcsv($f, $lineData, $delimiter);
}
fseek($f, 0);
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
fpassthru($f);
?>