Convert Json To Variable
i wont create MapData for jvectormap from database, like this {'AP':3,'DE':1,'GB':2,'ID':24,'US':10} but my code always return like this ['{\'AP\':3}','{\'DE\':1}','{\'GB\':2}','{\
Solution 1:
You need to parse the data to get an object you can get data from.
var mapData = JSON.parse(data);
Solution 2:
<php
$query = $this->db->query('SELECT country, COUNT(1) AS rpt_count FROM vistors GROUP BY country');
$rows = "{";
$data_count = 0;
$data_length = count($query);
foreach($query->result() as $row){
$key = $row->country;
$value = $row->rpt_count;
$rows .=$key.':'.$value;
$data_count +=1;
if($data_count != $data_length){
$rows .=',';
}
}
$rows .= "}";
return $rows;
Post a Comment for "Convert Json To Variable"