我有一个存储用户记录的问题的表,我想循环遍历表并计算每个用户记录的问题数量,然后在HTML表格中显示。这是我到目前为止,但它只适用于一个条目,然后不起作用。
<div class ="col-md-4">
<?php
$query = mysql_query("SELECT analyst_name FROM escalations");
echo "<table class='table'>
<tr>
<th>Analyst</th>
<th>Issues Logged</th>
</tr>";
while($row = mysql_fetch_array($query))
{
$analyst = $row['analyst_name'];
$issuesLogged = count($analyst);
echo "<td>" . $analyst . "</td>";
echo "<td>" . $issuesLogged . "</td>";
?>
<?php
echo "</tr>";
echo "</table>";
}
?>
</div>
答案 0 :(得分:2)
你最好在SQL中进行计数:
SELECT analyst_name, count(issuesLogged) as issue_total FROM escalations GROUP BY analyst_name