-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDataRegion.php
137 lines (119 loc) · 4.58 KB
/
getDataRegion.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
if(isset($_POST['subject_id']) &&
isset($_POST['region_id_sup']) &&
isset($_POST['region_id_sub'])) {
include('db.php');
$subject_id = $_POST['subject_id'];
$region_id_sup = $_POST['region_id_sup'];
$region_id_sub = $_POST['region_id_sub'];
$result = array();
$range = array(); //Regions [min, max] excluding Kyiv
$city_sup = array(); //Kyiv region_id = 26
$city_sub; //$region_id []
$averages = array("0","0","0","0","0","0","0","0","0");
$names = array(); //["subject", "Україна", "м.Київ", "region"]
//$get_range_min
$get_range_min = mysql_query("SELECT
MIN(ZNO2008) AS `2008`,
MIN(ZNO2009) AS `2009`,
MIN(ZNO2010) AS `2010`,
MIN(ZNO2011) AS `2011`,
MIN(ZNO2012) AS `2012`,
MIN(ZNO2013) AS `2013`,
MIN(ZNO2014) AS `2014`,
MIN(ZNO2015) AS `2015`,
MIN(ZNO2016) AS `2016`
FROM subjects
WHERE subject_id = ".$subject_id." AND region_id != '26' AND region_id != '27'");
while($row = mysql_fetch_row($get_range_min))
{
$range_min = $row;
}
foreach ($range_min as &$value) {
$value = round($value, 1);
}
//$get_range_max
$get_range_max = mysql_query("SELECT
MAX(ZNO2008) AS `2008`,
MAX(ZNO2009) AS `2009`,
MAX(ZNO2010) AS `2010`,
MAX(ZNO2011) AS `2011`,
MAX(ZNO2012) AS `2012`,
MAX(ZNO2013) AS `2013`,
MAX(ZNO2014) AS `2014`,
MAX(ZNO2015) AS `2015`,
MAX(ZNO2016) AS `2016`
FROM subjects
WHERE subject_id = ".$subject_id."
AND region_id != '26' AND region_id != '27'");
while($row = mysql_fetch_row($get_range_max))
{
$range_max = $row;
}
foreach ($range_max as &$value) {
$value = round($value, 1);
}
if ($subject_id == 8) {
$range_max[0] = null;
$range_min[0] = null;
$averages[0] = null;
}
//$format_range_array
for ($i=0; $i < sizeof($range_max); $i++) {
$temp = array();
array_push($temp,$range_min[$i]);
array_push($temp,$range_max[$i]);
array_push($range,$temp);
}
//$city_sup
$get_city_sup = mysql_query("SELECT ZNO2008, ZNO2009, ZNO2010, ZNO2011, ZNO2012, ZNO2013, ZNO2014, ZNO2015, ZNO2016
FROM subjects
WHERE subject_id = ".$subject_id." AND region_id = ".$region_id_sup."");
while($row = mysql_fetch_row($get_city_sup))
{
$city_sup = $row;
}
//$city_sub
$get_city_sub = mysql_query("SELECT ZNO2008, ZNO2009, ZNO2010, ZNO2011, ZNO2012, ZNO2013, ZNO2014, ZNO2015, ZNO2016
FROM subjects
WHERE subject_id = ".$subject_id." AND region_id = ".$region_id_sub."");
while($row = mysql_fetch_row($get_city_sub))
{
$city_sub = $row;
}
//$subject
$get_subject = mysql_query("SELECT subject
FROM subjects
WHERE subject_id = ".$subject_id." AND region_id = ".$region_id_sub."");
$names_subject = mysql_fetch_row($get_subject);
$names_subject = $names_subject[0];
$names_averages_title = "Україна";
$names_range_title = "Всі області";
$names_city_sup_name = mysql_query("SELECT region
FROM subjects
WHERE region_id = ".$region_id_sup."");
$names_city_sup_name = mysql_fetch_row($names_city_sup_name);
$names_city_sup_name = $names_city_sup_name[0];
$get_city_sub_name = mysql_query("SELECT region
FROM subjects
WHERE region_id = ".$region_id_sub."");
$names_city_sub_name = mysql_fetch_row($get_city_sub_name);
$names_city_sub_name = $names_city_sub_name[0];
array_push($names,$names_subject);
array_push($names,$names_averages_title);
array_push($names,$names_range_title);
array_push($names,$names_city_sup_name);
array_push($names,$names_city_sub_name);
//creating result array
array_push($result,$range);
array_push($result,$averages);
array_push($result,$city_sup);
array_push($result,$city_sub);
array_push($result,$names);
print json_encode($result, JSON_NUMERIC_CHECK);
mysql_close($con);
} else {
$empty = "false";
print $empty;
}
?>