this is the result of the query
this is the php query code
SELECT
FROM_UNIXTIME(add_time, "%Y-%m-%d") as add_time,
count(view_id) as viewTime
FROM `view`
GROUP BY `add_time`
this is the whole php code
header("Content-type: application/json");
$chartData = $pdo->query(
"SELECT
FROM_UNIXTIME(add_time, "%Y-%m-%d") as add_time,
count(view_id) as viewTime
FROM `view`
GROUP BY `add_time` "
);
$data = array();
$key = 0;
foreach ($chartData as $item){
$data[$key] = array(
"date" => $item["add_time"],
"number" => $item["viewTime"]
);
$keyPP;
}
echo json_encode($data);
print results
[{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"},{"date":"2018-08-16","number":"1"}.............
the viewTime on the right is all data
, but what I want to implement is
date duplicates as long as a
is shown, but the numbers of the same date are all added up
. How can this be achieved?
I"m going to print out a json like this at the back end
with a sense of principle if possible