In my database 'coordinates' there are four columns id bus_id latitude longitude where a user having a particular bus_is send its long, lat on a regular interval of time. I want to retrieve most updated value for each user. Here is my code:
<?php
define('HOST','localhost');
define('USER','root');
define('PASS','1234');
define('DB','coordinates');
$con = mysqli_connect(HOST,USER,PASS,DB);
$arr=[];
for($x=1; $x=3; $x++){
$query = "SELECT id, longitude, latitude FROM data WHERE bus_id= ".$x." ORDER BY id DESC limit 1 offset 1 " ;
$qry_result = mysqli_query($con,$query);// or die(mysqli_error());
}
// Insert a new row in the table for each person returned
while($row = mysqli_fetch_array($qry_result)) {
array_push($arr, [
'lat'=>['$latitude'],
'lng'=>['$longitude'],
//'recs'=>$recs
]);
}
$record= json_encode($arr);
echo $arr;
?>
when i run this code it doesn't give me right output. Please tell me where am i wrong.