-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgetStudentRecord.php
More file actions
74 lines (73 loc) · 2.46 KB
/
getStudentRecord.php
File metadata and controls
74 lines (73 loc) · 2.46 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
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$searchType = $_GET['searchBy'];
$key = $_GET['sKey'];
$eventType = $_GET['eventType'];
$eventID = $_GET['eventID'];
$eType = $_GET['eType'];
$curYear = date('Y');
$outp ="[";
$con=mysqli_connect("127.0.0.1","root","","project_test");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "";
if($eType == "sid"){
$sql .= "SELECT * FROM student WHERE AppID="."'".$key."'";
}
else if($eventType == "event"){
$sql .= "SELECT * FROM eventdetails e JOIN student st ON e.AppID = st.AppID WHERE EventID = ".$eventID." AND ";
if($searchType == 1){
$sql .= "st.AppID = ".$key.";";
}
else{
$sql .= "st.StudentID = ".$key.";";
}
}
else{
$sql .= "SELECT e.AppID AS AppID,s.SubjectID AS SubjectID,SubjectName,SeatNo,Room,e.Time AS Time FROM examroom e JOIN subject s ON e.SubjectID = s.SubjectID JOIN student st ON e.AppID = st.AppID WHERE ";
if($searchType == 1){
$sql .= "st.AppID = ".$key." AND ";
}
else{
$sql .= "st.StudentID = ".$key." AND ";
}
$sql .= "s.SubjectID = '".$eventID."' AND s.ED_year = ".$curYear.";";
}
//echo ($sql);
$result = $con->query($sql);
if($result->num_rows > 0 && $eType == "sid"){
// output data of each row
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"AppID":"' . $rs["AppID"] . '",';
$outp .= '"StudentID":"'. $rs["StudentID"] . '"}';
}
}
else if ($result->num_rows > 0 && $eventType == "exam") {
// output data of each row
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"AppID":"' . $rs["AppID"] . '",';
$outp .= '"SubjectID":"' . $rs["SubjectID"] . '",';
$outp .= '"SubjectName":"' . $rs["SubjectName"] . '",';
$outp .= '"SeatNo":"'. $rs["SeatNo"] . '",';
$outp .= '"Room":"' . $rs["Room"] . '",';
$outp .= '"Time":"'. $rs["Time"] . '"}';
}
}
else if($result->num_rows > 0 && $eventType == "event"){
// output data of each row
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"AppID":"' . $rs["AppID"] . '",';
$outp .= '"EventID":"' . $rs["EventID"] . '",';
$outp .= '"AttributeNo":"' . $rs["AttributeNo"] . '",';
$outp .= '"AttributeValue":"'. $rs["AttributeValue"] . '"}';
}
}
$outp.="]";
$con->close();
echo ($outp)
?>