-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataToJSON.php
79 lines (66 loc) · 2.72 KB
/
DataToJSON.php
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
<?php
require_once './include/db.php';
function getResponse($query) {
$result = mysql_query($query);
$response = array();
if (mysql_num_rows($result) > 1) {
while ($row = mysql_fetch_assoc($result)) {
array_push($response, $row);
}
} else if (mysql_num_rows($result) == 1) {
array_push($response, mysql_fetch_assoc($result));
}
return $response;
}
if (filter_input(INPUT_SERVER, "REQUEST_METHOD") == "GET") {
$response = array();
$table_name = trim(stripslashes(htmlspecialchars(filter_input(INPUT_GET, "table_name"))));
$linker = trim(stripslashes(htmlspecialchars(filter_input(INPUT_GET, "linker"))));
$link = trim(stripslashes(htmlspecialchars(filter_input(INPUT_GET, "link"))));
if ($table_name == "ALL" && $linker == "app_id" && $link > 0) {
$app_id = $link;
$response['chapters'] = array();
$response['chapters'] = getResponse(
'select * from chapters where app_id = ' . $app_id
);
$response['topics'] = array();
$response['topics'] = getResponse(
'select * from topics where chapter_id IN (
select id from chapters where app_id = ' . $app_id . '
)'
);
$response['numericals'] = array();
$response['numericals'] = getResponse(
'select * from numericals where topic_id IN (
select id from topics where chapter_id IN (
select id from chapters where app_id = ' . $app_id . '
)
)'
);
$response['formulas'] = array();
$response['formulas'] = getResponse(
'select * from formulas where numerical_id IN (
select id from numericals where topic_id IN (
select id from topics where chapter_id IN (
select id from chapters where app_id = ' . $app_id . '
)
)
)'
);
$response['parameters'] = array();
$response['parameters'] = getResponse(
'select * from parameters where chapter_id IN (
select id from chapters where app_id = ' . $app_id . '
)'
);
$response['units'] = array();
$response['units'] = getResponse(
'select * from units where chapter_id IN (
select id from chapters where app_id = ' . $app_id . '
)'
);
} else {
$response = getResponse("SELECT * FROM $table_name WHERE $linker = '$link'");
}
echo json_encode($response);
}