我已经从一个月的表数据编码json数组,如下所示,但如何组合所有数据后,如何将多个数据表与其他月份在一个json数组和GROUP BY部分组合?如何合并多个表数据并将json编码为一个数组?
<?php
include("dbconfig.php");
$sql = "SELECT dept, SUM(ttlot) AS sum_ot, SUM(ttlnorm) AS sum_norm
FROM month_jan
GROUP BY dept
ORDER BY sum_ot DESC";
$result = mysqli_query($dbconfig, $sql) or die("Error in Selecting " . mysqli_error($dbconfig));
$category = array();
$category['name'] = 'Dept';
$series1 = array();
$series1['name'] = 'Normal';
$series2 = array();
$series2['name'] = 'OT';
$emparray = array();
while ($row = mysqli_fetch_assoc($result)) {
$category['data'][] = $row['dept'];
$series1['data'][] = $row['sum_norm'];
$series2['data'][] = $row['sum_ot'];
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
$json = json_encode($result,JSON_NUMERIC_CHECK);
echo $json;
mysqli_close($dbconfig);
?>
产出月月:
[{"name":"Dept","data":["CNC","MACH","ANOD","BUFF","CAST","POLISH","SL","EPT","TUMB","TOOL","SHOT","QC","LOG","MAIN","LC","WWT","OG","NPD","E-COAT","SFT"]},{"name":"Normal","data":[47429.1,39975.7,34553.8,49075.9,28316.3,21237.1,13492.5,5848.2,7691.1,6963.9,5636.1,7555.8,5821.9,2161.2,1812,1191.7,1479.1,1299.6,11542.6,602]},{"name":"OT","data":[20041,17874,14431,13535.5,8800.5,5613.5,3569.5,3101,2327,2278,2237,2142,1810,942,690,456,297,110.5,66,50.5]}]
什么结果,我结合四个月后,想:
[{"name":"Month","data":["Jan","Feb","Mac","Apr"]},{"name":"Normal","data":[504291,409757,295538,430759]},{"name":"OT","data":[89041,96874,81431,80535]}]
有谁可以帮我解决这个问题?