<?php
$json = "{
\"Data 1\": {
\"Text1\": \"Anything1\",
\"Text2\": \"Anything2\"
},
\"Data 2\": {
\"2018-08-02\": {
\"1.\": \"145\",
\"2.\": \"258\"
},
\"2018-08-03\": {
\"1.\": \"428\",
\"2.\": \"528\"
},
\"2018-08-04\": {
\"1.\": \"727\",
\"2.\": \"514\"
}
}
}";
$jsonDecoded = json_decode($json, true);
foreach ($jsonDecoded['Data 2'] as $dateKey => $data) {
//$values = '';
//foreach ($data as $datum) {
// $values .= $datum . ',';
//}
$values = implode(',', $data);
$statement = "INSERT INTO mytable (TheDate, Value1, Value2) VALUES ('{$dateKey}'," . $values . ");";
echo $statement . PHP_EOL;
}
preferences:
25.48 ms | 405 KiB | 5 Q