want to retrieve a records data from Mysql and store it into Javascript array for heatmap.js map data in this format :
var testData = {max: 46, data: [{lat: 33.5363, lon:-117.044, value: 1},{lat: 33.5608, lon:-117.24, value: 1},..]};
Now I get stuck at here, and I don't know how to connecting from Jquery into my var testData = new Array();
, How I should do to solve this?
(UPDATED CORRECT CODE)
get_query.php
<?php
require_once('./db_con.php');
$dbcon=new db;
$query="SELECT (SELECT geo_lat FROM fun WHERE created_at <= DATE_SUB(NOW(), interval 1 minute) AS geo_lat," .
"(SELECT geo_long FROM fun WHERE created_at <= DATE_SUB(NOW(), interval 1 minute) AS geo_long";
$result = mysqli_query($dbcon,$query);
$data = array();
while($row= mysqli_fetch_assoc($result)){
$data[] = array("lat"=>$row["geo_lat"], "lon"=>$row["geo_long"], "value"=>1);
$post_data = json_encode(array('max' => 46, 'data' => $data));
}
echo $post_data;
?>
my_data.js based from here:
jQuery.extend({
getValues: function(url) {
var result = null;
$.ajax({
url: url,
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
result = JSON.stringify(data);
}
});
return result;
}
});
var testData = $.getValues("get_query.php");
Thanks to Orangepill and Chrislondon.
while(true){
?while(true){
?json_encode
should only be called once, at the very end, once the array is built the way you want it.