У меня проблемы с этим.Я застрял на это на пару часов.Я хотел, чтобы диапазон дат отображался в виде другого столбца в запросе.поэтому у меня есть этот запрос
SELECT id, created,
COUNT(IF(DATE(created) = "2019-02-01",1, null)) AS "2019-02-01",
COUNT(IF(DATE(created) = "2019-02-01",2, null)) AS "2019-02-02",
COUNT(IF(DATE(created) = "2019-02-03",1, null)) AS "2019-02-03",
COUNT(IF(DATE(created) = "2019-02-04",1, null)) AS "2019-02-04",
COUNT(IF(DATE(created) = "2019-02-05",1, null)) AS "2019-02-05"
FROM logs WHERE DATE(created) = "2019-02-01" AND message= 'Login' AND username = 'aaa@example.com';
И у меня есть этот результат для запроса выше ![this is the reult when execute the query](https://i.stack.imgur.com/bqQGU.png)
Таким образом, чтобы преобразовать его в cakephp таким образом, что я сделал
$start = strtotime($start_date);
$end = strtotime($end_date);
$dates = [];
for ($currentDate = $start; $currentDate <= $end;
$currentDate += (86400)) {
$Store = date('Y-m-d', $currentDate);
$dates[] = $Store;
}
foreach ($dates AS $d) {
$logs = $this->Log->find("all", [
'fields' => ['Log.id',
'Log.created',
'COUNT(IF(DATE(Log.created) = "'.$d.'",1, null)) AS "'.$d.'"'
],
'conditions' => $conditions,
]);
Но этот код дает мне другой вывод.Отображается только одна дата
Array
(
[0] => Array
(
[Log] => Array
(
[id] => 46260
[created] => 2019-02-05 11:10:12
)
[0] => Array
(
[2019-02-05] => 1
)
)
)
То, что я ожидаю, будет выглядеть примерно так:
Array
(
[0] => Array
(
[Log] => Array
(
[id] => 46260
[created] => 2019-02-05 11:10:12
)
[Date] => Array
(
[2019-02-01] => 4,
[2019-02-02] => 0,
[2019-02-03] => 0,
[2019-02-04] => 0,
[2019-02-05] => 0,
)
)
)
Я хочу знать, что не так с моей работой и как ее исправить.Заранее благодарим за помощь