-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetProbs.php
More file actions
40 lines (33 loc) · 1.04 KB
/
Copy pathgetProbs.php
File metadata and controls
40 lines (33 loc) · 1.04 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
<?php
include_once 'dbh.inc.php';
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
$json = file_get_contents('php://input');
$obj = json_decode($json, true);
$pointAsc = "SELECT * FROM problems ORDER BY pPoint ASC";
$pointDesc = "SELECT * FROM problems ORDER BY pPoint DESC";
$subAsc = "SELECT * FROM problems ORDER BY pSub ASC";
$subDesc = "SELECT * FROM problems ORDER BY pSub DESC";
if (isset($obj)) {
$rank = $obj['rank'];
if ($rank == 'points') {
$sql = $pointDesc;
} else if ($rank == 'sub') {
$sql = $subDesc;
} else if ($rank == 'apoints') {
$sql = $pointAsc;
}else if ($rank == 'asub') {
$sql = $subAsc;
}else {
$sql = $pointDesc;
}
$result = mysqli_query($conn, $sql);
$probs = array();
while ($row = mysqli_fetch_assoc($result)) {
$probs[] = $row;
}
echo json_encode(array('probs' =>$probs, 'rank' =>$rank));
} else {
echo json_encode(array('error' => 'no rank'));
}