forked from NishantRaj/ISM-Shuttle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
36 lines (34 loc) · 999 Bytes
/
index.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
<?php
include "connect_database.php";
$table_name = "bus_pos_1";
$obj = new Connect_database();
$conn = $obj->connect_db();
if (count($_GET)){
if ($_GET['latest'] == null){
$lat = $_GET['lat'];
$long = $_GET['long'];
$speed = $_GET['speed'];
$v = date_create();
$ts = $v->format('Y-m-d H:i:s');
$q = "INSERT INTO ".$table_name." (latitude, longitude, speed, ts) ".
"VALUES ('$lat', '$long', '$speed', '$ts')";
mysql_query($q, $conn);
}
else{
$q1 = "SELECT MAX( id ) FROM ". $table_name;
$id_res = mysql_query($q1, $conn);
$id_row = mysql_fetch_array($id_res);
$id = $id_row[0];
$q = "SELECT latitude, longitude, speed, ts FROM ".$table_name." WHERE id = '$id'";
$res = mysql_query($q, $conn);
while ($row = mysql_fetch_array($res)){
$arr = array('latitude' => $row['latitude'],
'longitude' => $row['longitude'],
'speed' => $row['speed'],
'ts' => $row['ts']);
header('Content-type: application/json');
echo json_encode($arr);
}
}
}
?>