-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_batches.php
More file actions
45 lines (37 loc) · 1.01 KB
/
get_batches.php
File metadata and controls
45 lines (37 loc) · 1.01 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
<?php
session_start();
require_once 'db_connection.php';
// Check if user is logged in and has appropriate role
if (!isset($_SESSION['role']) || !in_array($_SESSION['role'], ['hod', 'faculty'])) {
header('Content-Type: application/json');
echo json_encode(['error' => 'Unauthorized']);
exit();
}
// Get degree from request
$degree = $_GET['degree'] ?? '';
// Prepare query
$query = "SELECT DISTINCT passing_year FROM alumni_survey";
$params = [];
$types = '';
if ($degree) {
$query .= " WHERE degree = ?";
$params[] = $degree;
$types = 's';
}
$query .= " ORDER BY passing_year DESC";
// Execute query
$stmt = mysqli_prepare($conn, $query);
if (!empty($params)) {
mysqli_stmt_bind_param($stmt, $types, ...$params);
}
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
// Fetch results
$batches = [];
while ($row = mysqli_fetch_assoc($result)) {
$batches[] = $row['passing_year'];
}
// Return JSON response
header('Content-Type: application/json');
echo json_encode($batches);
?>