我正在尝试从 MySQL 查询创建多维数组
询问:
$STH = $DBH->query( "SELECT value, o_ID, oName, date,
DATE_FORMAT(date, '%d %m %Y') as FDate,
DATE_FORMAT(tsTime, '%H:%i') as FTime
FROM test tst
LEFT JOIN object o
ON tst.o_ID =o.oID
WHERE DATE(date) = '$date'
ORDER BY FDate, FTime, oName ASC");
$STH->setFetchMode(PDO::FETCH_ASSOC);
环形:
$returnValue = array();
$data = array();
while ( $row = $STH->fetch() ) {
$returnValue[$row['oName']] =
array(
$data[] = array(
'time' => $row['FTime'], 'value' => $row['value']
)
);
}
输出:
{"objectA":[{"time":"23:55","value":"15"}],"objectB":[{"time":"23:55","value":"15.90"}],..}
如何将所有值放入 $data 数组中?
期望的输出:
{"objectA":[{"time":"01:00","value":"15"},{"time":"02:00","value":"11"},{"time":"03:00,"value":"16"}],"objectB":[{"time":""01:00","value":"12"},{"time":""02:00","value":"25"},{"time":""03:00","value":"5"}],..}