-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschoolWise.php
More file actions
167 lines (147 loc) · 5.13 KB
/
schoolWise.php
File metadata and controls
167 lines (147 loc) · 5.13 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body class="d-flex flex-column align-items-center" style="background-color: #FFE6EE">
<h1 style="color: #3f2b96; margin-top: 20px">School Wise Enrollment</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="dropdown" style="margin: 30px; display: inline">
<select id="select1" name="semester">
<option value="#">Semester</option>
<option value="Spring">Spring</option>
<option value="Summer">Summer</option>
<option value="Autumn">Autumn</option>
</select>
</div>
<div class="dropdown" style="margin: 30px; display: inline">
<select id="select2" name="year">
<option value="#">Year</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
</select>
</div>
<input
class="btn btn-primary"
type="submit"
value="View"
style="margin: 30px; display: inline"
/>
</form>
<table class="table" style="width: 800px">
<thead>
<tr>
<th scope="col">SBE</th>
<th scope="col">SELS</th>
<th scope="col">SETS</th>
<th scope="col">SLASS</th>
<th scope="col">SPPH</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$semester = $_POST['semester'];
$year = $_POST['year'];
if (empty($semester) || empty($year)) {
echo "Select from drop down menu!";
}
else if($semester=='Summer' && $year=='2020'){
echo "No Data";
}
else{
$servername = "localhost";
$username = "username";
$password = "";
$database = "spms 3.0";
$connection = new mysqli($servername, $username, $password, $database);
if($connection->connect_error){
die("Connection failed: " . $connection->connect_error);
}
$sql = "SELECT
SUM(CASE WHEN C.school_title='SBE' THEN CS.enrolled*C.credit_hour END) as SBE,
SUM(CASE WHEN C.school_title='SETS' THEN CS.enrolled*C.credit_hour END) as SETS,
SUM(CASE WHEN C.school_title='SELS' THEN CS.enrolled*C.credit_hour END) as SELS,
SUM(CASE WHEN C.school_title='SLASS' THEN CS.enrolled*C.credit_hour END) as SLASS,
SUM(CASE WHEN C.school_title='SPPH' THEN CS.enrolled*C.credit_hour END) as SPPH,
SUM(CS.enrolled*C.credit_hour) as Total
FROM course_section as CS, course as C WHERE CS.courseId=C.courseId AND semester = '$semester' AND year = '$year' AND CS.blocked IN ('-1', '0') GROUP BY year, semester;";
$result = $connection->query($sql);
if (!$result){
die("Invalid query: " . $connection->error);
}
while($row = $result->fetch_assoc()){ echo "
<tr>
<td>$row[SBE]</td>
<td>$row[SELS]</td>
<td>$row[SETS]</td>
<td>$row[SLASS]</td>
<td>$row[SPPH]</td>
<td>$row[Total]</td>
</tr>
"; }
foreach($result as $data){
$sbe = $data['SBE'];
$sels = $data['SELS'];
$sets = $data['SETS'];
$slass = $data['SLASS'];
$spph = $data['SPPH'];
$total = $data['Total'];
}
}
}
?>
</tbody>
</table>
<div style="width: 800px; margin: 50px">
<canvas id="myChart"></canvas>
</div>
<script>
const ctx = document.getElementById('myChart');
const labels = ["SBE","SELS","SETS","SLASS","SPPH"]
const data = {
labels: labels,
datasets: [{
label: 'SBE',
data: [<?php echo json_encode($sbe)?>, <?php echo json_encode($sels)?>, <?php echo json_encode($sets)?>, <?php echo json_encode($slass)?>,<?php echo json_encode($spph)?>],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(255, 159, 64, 0.2)',
'rgba(255, 205, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(54, 162, 235, 0.2)'
],
borderColor: [
'rgb(255, 99, 132)',
'rgb(255, 159, 64)',
'rgb(255, 205, 86)',
'rgb(75, 192, 192)',
'rgb(54, 162, 235)'
],
borderWidth: 1
}]
};
const config = {
type: 'bar',
data: data,
options: {
responsive: true,
plugins: {
legend: {
display: false,
position: 'bottom',
}
}
},
};
new Chart(ctx, config);
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
</body>
</html>