0

Here's my code:

<?php 

session_start();

$con = mysqli_connect('localhost', 'id128XXXXX', 'LXXXX');

mysqli_select_db($con, 'idXXXXXX');

$query = "select * from sensor order by id desc limit 1";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_array($result);


$value = array( 
    "geometry"=>array( 
        "type"=> "Point", 
        "coordinates"=> [0,0] ///I want to get values from a database and put it in this bracket.
    ) , 

    "type"=>"Feature", 
    "properties" => (object) array()
); 

// Use json_encode() function 
$json = json_encode($value); 

// Display the output 
echo($json); 

?> 

Any help regarding this will be much appreciated thank you. As for what I've tried. I tried using

 "coordinates"=> [$row[longitude],$row[lat]]

ended up giving me this type of output:

{"geometry":{"type":"Point","coordinates":["0","0"]},"type":"Feature","properties":{}} 

i need the ["0","0"] to be [0,0] since with the added quotation marks the map marker will not show up. And if anyone is asking I'm using mapbox and i need to output this json data for the map marker to keep refreshing.

  • More specifically https://stackoverflow.com/a/6608413/1213708 which would be something like `$json = json_encode( $value, JSON_NUMERIC_CHECK )` – Nigel Ren Mar 14 '20 at 19:37

1 Answers1

0

Convert the results to integers:

"coordinates"=> [intval($row['longitude']), intval($row['lat'])]

And don't forget to quote strings longitude and lat.

Barmar
  • 741,623
  • 53
  • 500
  • 612