-
Notifications
You must be signed in to change notification settings - Fork 16
/
generatefile.php
64 lines (58 loc) · 1.94 KB
/
generatefile.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// Database Connection
require("config.php");
session_name("staff");
session_start();
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: staff_login.php");
exit;
}
// get users list
$cgpa = $_SESSION["cgpa"];
$backlog = $_SESSION["backlog"];
$company=$_SESSION['company'];
$query = "select * from marks where cgpa >= '$cgpa' and backlogs <='$backlog'";
if (!$result = mysqli_query($conn, $query)) {
exit(mysqli_error($conn));
}
$users = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$users[] = $row;
}
}
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=users-sample.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('RegdNo','Name','Email','Contact','D.O.B', 'Cgpa', 'Backlogs' ,'Company'));
/*if (count($users) > 0) {
foreach ($users as $row) {
fputcsv($output, $row);
}
}*/
$row4=array();
if(count($users)>0){
foreach($users as $row){
$regd=$row["regdno"];
$query2= "select * from student where regdno='$regd'";
if (!$result2 = mysqli_query($conn, $query2)) {
exit(mysqli_error($conn));
}
if (mysqli_num_rows($result2) > 0) {
while ($row2 = mysqli_fetch_assoc($result2)) {
$users2[] = $row2;
}
}
if(count($users2)>0){
foreach($users2 as $row2){
}
}
$row3=array_merge($row2,$row);
array_push($row3,$company);
unset($row3['password']);
fputcsv($output,$row3);
/*print_r($row2['name']);
print_r($row["regdno"]);*/
}
}
?>