date_start=='') $object->date_start='null'; if($object->date_end=='') $object->date_end='null'; require_once("../../monitoring/config.php"); $db = connectToDB(); $db->exec('SET TIME ZONE 0;'); $sql = 'select id,lon,lat,round(extract(epoch from date at time zone \'utc\')) udate,speed,velocity from main.terminals_locations where del=false and object_id='.$object->object_id.' and ('.$object->date_start.' is null or date > to_timestamp('.$object->date_start.')::timestamp) and ('.$object->date_end.' is null or date < to_timestamp('.$object->date_end.')::timestamp) order by date;'; try { $res = $db->query($sql); }catch (Exception $e) { echo $e->getMessage(); $res = null; } //Массив объектов $json ='['; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $json .="\n"; $json .='{'; $json .='"lat":"'.$row['lat']."\",\n"; $json .='"lon":"'.$row['lon']."\",\n"; $json .='"udate":"'.$row['udate']."\",\n"; $json .='"speed":"'.round ($row['speed'], 1)."\",\n"; $json .='"velocity":"'.round ($row['velocity'], 1)."\"\n"; $json .='},'; } if($json!='[') $json = substr($json,0,strlen($json)-1); $json .=']'; header('Content-Type: application/json'); echo $json;