0

我正在运行此查询并获得结果:

|  COUNT(DISTINCT member_extension)  |  queue_name        |  queue_account_id
|  21                                |     Standard       |  1105
|  16                                |     Premium        |  1133
|  21                                |     WorldMark      |  1202
|  8                                 |     Escalation     |  1248
|  17                                |     Wingate Queue  |  1249

但是,当我尝试将 member_extension COUNT() 放在一个表中时,我似乎无法显示它们。我究竟做错了什么?

我收到此错误:

注意:未定义索引:第 59 行 C:\Apache24\htdocs\phone-dashboard\testing\count_test.php 中的 member_extension

$sth = $conn->prepare("SELECT COUNT(DISTINCT member_extension),     queue_name,`queue_account_id`
FROM CallLog
WHERE type = 'completed'
BETWEEN '2013-10-22 09:00:00'
AND '2013-10-24 09:00:00'
GROUP BY queue_account_id
"); 
$sth->execute();
$sql = $sth->fetchAll(PDO::FETCH_ASSOC);

echo '<table>';
echo "<tr><td>" . 'Queue Name' . "</td><td>" . 'Queue Account ID' . "</td><td>" . 'Queue Total' . "</td></tr>";
try {   
    foreach ($sql as $rs) {
        echo '<tr>';
        echo '<td>' . $rs['queue_name'] . '</td>';
        echo '<td>' . $rs['queue_account_id'] . '</td>';
        echo '<td>' . $rs['member_extension'] . '</td>';
        echo '</tr>';
        }

    echo '</table>';
    }
catch (PDOException $e) {
print $e->getMessage();
}
?>
4

1 回答 1

2

给计数一个别名,您可以轻松引用:

SELECT COUNT(DISTINCT member_extension) AS num_extensions


foreach ($sql as $rs) {
    echo '<tr>';
    echo '<td>' . $rs['queue_name'] . '</td>';
    echo '<td>' . $rs['queue_account_id'] . '</td>';
    echo '<td>' . $rs['num_extensions'] . '</td>';
    echo '</tr>';
    }
于 2013-10-24T15:27:18.843 回答