I've a php query which creates the JSON data of the the data received from the SQL query that is run. The JSON data is created using this query using this query
echo json_encode($res->fetch_all(MYSQLI_ASSOC), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT );
Now I want to plot a chart using fusionchart for which I need to convert this data into an array. I tried a sample JS code to convert the JSON data into an JS array and it worked
var data = { "timestamp": "2016-09-23", "value1": "0", "value2": "0", ........., "value49": "0", "value50": "0" };
var arr = [];
for (elem in data) {
arr.push(data[elem]);
}
console.log(arr);
Now in the data variable I need to pass the data from php code. This is just one of the records that I entered manually. There are over a million records and I need to convert all of them. How I do this?
$resis a result set, not an array. You need to store the result in a variable. Instead ofecho json_encode($res->...), do$data = json_encode($res->..). Then you can echo the$datavariable where ever you want.