01.
$fetch_users = mysqli_query($
connect
,
"
02.
SELECT id, type, company, COUNT(*) AS countcompany, COUNT(type) AS counttype
03.
FROM users
04.
GROUP BY company, type"
)
or
die(mysqli_error($
connect
));
05.
while ($row = mysqli_fetch_assoc($fetch_users)) {
06.
$row_array[$row[
'company'
]][
'ทั้งหมด'
] = $row[
'countcompany'
];
07.
$row_array[$row[
'company'
]][
'ประเภท'
][] = array(
08.
09.
$row[
'type'
] => $row[
'counttype'
],
10.
);
11.
12.
}
13.
14.
$json_data = array(
'Operator_OSEC'
=> $row_array);
15.
$json = json_encode($json_data);
16.
17.
//file_put_contents(
'demo.json'
, $json);
18.
19.
echo $json;
20.
21.
mysqli_close($
connect
);
22.
23.
exit;