-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistics.php
90 lines (84 loc) · 3.63 KB
/
statistics.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
require 'constants.php';
$input = json_decode($_POST["x"], false);
$sql = '';
// Create connection
$conn = new mysqli($db_server, $db_username, $db_password, $db_name);
// check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$value = $input->value;
$total = 0;
switch ($value) {
case '1':
$sql = 'select workshop_id, count(*) as cnt from register_details group by workshop_id;';
$result = $conn->query($sql);
if($result->num_rows > 0) {
echo "<table border='1' id=\"tblData\"><tr><td>workshop_id</td><td>count</td></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td> " . $row["workshop_id"] ."</td><td>" .$row["cnt"] . "</td></tr>";
$total = $total + $row['cnt'];
}
echo "<tr><td> TOTAL </td><td>" . $total . "</td>";
echo "</table>";
}
# code...
break;
case '2':
$sql = 'select workshop_id, college, count(*) as cnt from user_details,register_details where user_details.user_id = register_details.user_id group by workshop_id, college';
$result = $conn->query($sql);
if($result->num_rows > 0) {
echo "<table border='1' id=\"tblData\"><tr><td>workshop_id</td><td>College name</td><td>count</td></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td> " . $row["workshop_id"] ."</td><td>" . $row['college'] . "</td><td>" .$row["cnt"] . "</td></tr>";
$total = $total + $row['cnt'];
}
echo "</table>";
}
# code...
break;
// Not yet finished
case '3':
$sql = 'select workshop_id, email_id,name,phone_number,college from user_details, register_details where register_details.user_id = user_details.user_id';
$result = $conn->query($sql);
if($result->num_rows > 0) {
echo "<table border='1' id=\"tblData\"><tr><td>workshop_id</td><td>Email</td><td>name</td><td>Phone number</td><td>College</td></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td> " . $row["workshop_id"] ."</td><td>" . $row['email_id'] . "</td><td>" .$row["name"] . "</td><td>" .$row["phone_number"] . "</td><td>" .$row["college"] . "</td></tr>";
$total = $total + $row['cnt'];
}
echo "</table>";
}
# code...
break;
case '4':
$sql = 'select name, email_id, phone_number, college, year_of_study from user_details where bought_entry = 1';
$result = $conn->query($sql);
if($result->num_rows > 0) {
echo "<table border='1' id=\"tblData\"><tr><td>name</td><td>Email</td></td><td>phone_number</td><td>college</td><td>year_of_study</td></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td> " . $row["name"] ."</td><td>" . $row['email_id'] . "</td><td>" .$row["phone_number"] . "</td><td>" .$row["college"] . "</td><td>" .$row["year_of_study"] . "</td></tr>";
}
echo "</table>";
}
# code...
break;
case '5':
$sql = 'select name, check_in, check_out, phone_number, email_id from user_details where check_in is NOT NULL and check_out is NOT NULL';
$result = $conn->query($sql);
if($result->num_rows > 0) {
echo "<table border='1' id=\"tblData\"><tr><td>name</td><td>check_in</td><td>check_out</td><td>phone_number</td><td>Email</td></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td> " . $row["name"] ."</td><td>" . $row['check_in'] . "</td><td>" .$row["check_out"] . "</td><td>" .$row["phone_number"] . "</td><td>" .$row["email_id"] . "</td></tr>";
}
echo "</table>";
}
# code...
break;
default:
# code...
break;
}
echo "<button onclick=\"download('tblData')\">DOWNLOAD</button>";
?>