forked from titat/project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetQuery12.php
More file actions
20 lines (16 loc) · 983 Bytes
/
getQuery12.php
File metadata and controls
20 lines (16 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$conn = new mysqli("127.0.0.1", "root", "", "project_test");
$result = $conn->query("SELECT sCount*100/totalS AS percent,sub2.AppType,sub2.CourseName FROM ( SELECT sub1.totalS,COUNT(*)AS sCount,app.AppType,c.CourseName FROM (SELECT COUNT(*)AS totalS,s.AppTypeID FROM student s GROUP BY s.AppTypeID) AS sub1 JOIN student s ON s.AppTypeID = sub1.AppTypeID JOIN apptype app ON s.AppTypeID = app.AppTypeID JOIN student_course sc ON s.AppID = sc.AppID JOIN course c ON sc.CourseID = c.CourseID GROUP BY c.CourseID,app.AppTypeID ) AS sub2 ORDER BY AppType");
$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "[") {$outp .= ",";}
$outp .= '{"percent":"' . $rs["percent"] . '",';
$outp .= '"AppType":"' . $rs["AppType"] . '",';
$outp .= '"CourseName":"'. $rs["CourseName"] . '"}';
}
$outp .="]";
$conn->close();
echo($outp);
?>