forked from shinobushiva/Water
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
51 lines (35 loc) · 986 Bytes
/
api.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
<?php
header('Content-Type: application/json');
date_default_timezone_set('asia/tokyo');
require_once('dbconnect.php');
$connect = open_db();
mysqli_query($connect, 'SET NAMES utf8');
mysqli_set_charset($connect, 'utf8');
mysqli_select_db($connect, '');
$end = $_GET['map_end'];
$from_time = $_GET['map_start'];
$flg = explode(",", $_GET["map_flg"]);
$query = 'select * from info where time > ' . $from_time . ' AND time < ' . $end;
if(!empty($flg)){
$query .= " AND (";
foreach($flg as $f){
$query .= " flg =" . $f;
if ($f !== end($flg)) {
$query .= " OR ";
}
}
$query .= " ) ";
}
$res = mysqli_query($connect, $query);
function json_safe_encode($data)
{
return json_encode($data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
}
$arr = array();
while ($data = mysqli_fetch_array($res)) {
$arr[] = $data;
}
$json = json_safe_encode($arr);
//error_log($json);
mysqli_close($connect);
echo $json;