php - Get MySql data and store it into Javascript array -
want retrieve records data mysql , store javascript array heatmap.js map data in format :
var testdata = {max: 46, data: [{lat: 33.5363, lon:-117.044, value: 1},{lat: 33.5608, lon:-117.24, value: 1},..]};
now stuck @ here, , don't know how connecting jquery var testdata = new array();
, how should solve this?
(updated correct code)
get_query.php
<?php require_once('./db_con.php'); $dbcon=new db; $query="select (select geo_lat fun created_at <= date_sub(now(), interval 1 minute) geo_lat," . "(select geo_long fun created_at <= date_sub(now(), interval 1 minute) 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 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 orangepill , chrislondon.
so question how connect jquery var data
won't myriad of problems in php code. in success function can set var data
so:
var data = new array(); $(function() { $.ajax({ type: "post", url: "get_query.php", data: $(this).serialize(), datatype: "json" }).done(function(response) { data = response; });
Comments
Post a Comment