只有最后一个值被添加到循环中。我找不到我犯错误的地方。你可以做些什么来帮忙吗?
<?php
$pdo = $this->getEntityManager()->getPDO();
$users = $this->getUserList();
foreach ($users as $user) {
$sql = "SELECT
COUNT( assigned_status ) AS 'Adet',
SUM( CASE WHEN m.assigned_status = 'Olumlu' THEN 1 ELSE 0 END ) AS Olumlu,
SUM( CASE WHEN m.assigned_status = 'Olumsuz' THEN 1 ELSE 0 END ) AS Olumsuz,
SUM( CASE WHEN m.assigned_status = 'Satış' THEN 1 ELSE 0 END ) AS Satış,
SUM( CASE WHEN m.assigned_status = 'Ertelenme' THEN 1 ELSE 0 END ) AS Ertelenme
FROM
meeting m
WHERE
assigned_user_id = '" . $user['user_id'] . "'";
$sth = $pdo->prepare($sql);
$sth->execute();
$data = $sth->fetchAll(\PDO::FETCH_ASSOC);
$resultData = array();
foreach ($data as $row) {
$resultData['Olumlu'] = array(
$user['full_name'] => array('Fly Team' => intval($row['Olumlu']))
);
}
}
return $resultData;
答案 0 :(得分:2)
错误在这里
foreach ($data as $row) {
$resultData['Olumlu'] = array(
$user['full_name'] => array('Fly Team' => intval($row['Olumlu']))
);
}
更改为
foreach ($data as $row) {
$resultData['Olumlu'][] = array(
$user['full_name'] => array('Fly Team' => intval($row['Olumlu']))
);
}
答案 1 :(得分:0)
你必须这样试试
$resultData = array();
foreach ($data as $row) {
$resultData[]['Olumlu'] = array(
$user['full_name'] => array('Fly Team' => intval($row['Olumlu']))
);
}
这对你有用