I'm trying to get a JSON-file looking like this:
[
[
'Disease', [ latitude, longitude, magnitude, latitude, longitude, magnitude, ... ]
],
[
'Disease', [ latitude, longitude, magnitude, latitude, longitude, magnitude, ... ]
]
];
This is what I've done:
<?php
$sqlDisease = mysql_query("SELECT DISTINCT Disease FROM DiseaseData") or die(mysql_error());
while($rowDisease = mysql_fetch_assoc($sqlDisease)){
$sqlData = mysql_query("
SELECT lat, lng, magnitude
FROM DiseaseData
WHERE Disease = '".$rowDisease."'")
or die(mysql_error());
while($rowData = mysql_fetch_assoc($sqlData)){
$data[] = array_values($rowData);
}
$result[] = array_values($rowDisease, $data);
}
$json = json_encode($result);
$file = 'testRes.json';
file_put_contents($file, $json);
I end up with a JSON-file looking like this:
[null,null,null]
The problem probably lies within the nested while-loops or array_values(), but I can't figure out exactly where.
$data[] = implode($rowData);instead ofarray_values