-
Notifications
You must be signed in to change notification settings - Fork 0
/
nowplace.php
54 lines (46 loc) · 1.69 KB
/
nowplace.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
<?php
//現在地取得
header('Content-Type: text/json; charset=utf-8');
// //Ajax通信ではなく、直接URLを叩かれた場合はエラーメッセージを表示
// if (
// !(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
// && (!empty($_SERVER['SCRIPT_FILENAME']) && 'json.php' === basename($_SERVER['SCRIPT_FILENAME']))
// )
// {
// die ('このページは直接ロードしないでください。');
// }
try {
$teacher_id = $_POST["teacher_id"];
// データベース接続
$mysqli = new mysqli("172.18.86.209","labUser","kawa4ken","future_prediction");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$mysqli->query("SET NAMES 'utf8'");
$query = "select * from trn_location_info where id = (select max(id) from trn_location_info where teacher_id = $teacher_id);";
$result = $mysqli->query($query);
// 取得したデータを配列に格納
while ($row = $result->fetch_array()){
$beacon_id_xy = $row['beacon_id'];
$query_xy = "select * from mst_room where id = $beacon_id_xy";
$result_xy = $mysqli->query($query_xy);
$row_xy = $result_xy->fetch_array();
$json[] = array(
'floor_id' => $row_xy['floor_id'],
'x' => $row_xy['x'],
'y' => $row_xy['y'],
'width' => $row_xy['width'],
'height'=> $row_xy['height'],
);
}
header('Content-Type: application/json');
echo json_encode( $json );
$mysqli->close();
}
catch (PDOException $e)
{
//例外処理
die('Error:' . $e->getMessage());
}
?>