In the two versions of code below, the first produces results but note that there is no end bracket at the end of the "text" array as there should be. The second output which comes from the other code example SEEMS like it should work but it fails completely. Where did I go wrong?
when I do this;
foreach($db_found->query($sql) as $row) {
$json_array[] =
array('start_date' =>
array('minute' => $row[min], 'hour' => $row[hour],
'month' => $row[mo], 'day' => $row[day], 'year' => $row[yr]),
'text' =>
array('text' => $row[text],
'group' =>
array('group' => $row[callsign])))
;
}
$data = array("events" => $json_array);
echo json_encode($data);
I get this:
{
"events":[
{
"start_date":{
"minute":"42",
"hour":"18",
"month":"11",
"day":"11",
"year":"2019"
},
"text":{
"text":"BILL SWEENEY Opened the net from 65.255.143.178 on 146.655MHz, PL94.8Hz",
"group":{
"group":"W0WTS"
}
}
},
{
"start_date":{
"minute":"42",
"hour":"18",
"month":"11",
"day":"11",
"year":"2019"
},
"text":{
"text":"Peculiar: Clear, 19.9F, wind: N @ 15, humidity: 54%",
"group":{
"group":"GENCOMM"
}
}
}
]
}
But what I need is this:
{
"events":[
{
"start_date":{
"minute":"42",
"hour":"18",
"month":"11",
"day":"11",
"year":"2019"
},
"text":{
"text":"BILL SWEENEY Opened the net from 65.255.143.178 on 146.655MHz, PL94.8Hz"
},
"group":{
"group":"W0WTS"
}
},
{
"start_date":{
"minute":"42",
"hour":"18",
"month":"11",
"day":"11",
"year":"2019"
},
"text":{
"text":"Peculiar: Clear, 19.9F, wind: N @ 15, humidity: 54%"
},
"group":{
"group":"GENCOMM"
}
}
]
}
I have also tried:
foreach($db_found->query($sql) as $row) {
$json_array[] =
array('start_date' =>
array('minute' => $row[min], 'hour' => $row[hour],
'month' => $row[mo], 'day' => $row[day], 'year' => $row[yr]),
array('text' =>
array('text' => $row[text]),
array('group' =>
array('group' => $row[callsign]))
;
}
$data = array("events" => $json_array);
echo json_encode($data);
But that doesn't work at all. What am I doing wrong.
'text' => array('text' => $row[text],here you are doing the mistake, just close the parenthesis before the comma and you are good to go, like'text' => array('text' => $row[text]),