答案 0 :(得分:0)
为您的COUNT(*)
使用别名,即resourceCount
SELECT username, primary_function, COUNT(*) as resourceCount
然后使用primary_function
和resourceCount
$resourceCounts = array();
while ($rowCounts = mysqli_fetch_assoc($countresult)) {
$resourceCounts['primary_function'] = $rowCounts['resourceCount'];
}
然后在您的表中,使用$row['primary_function']
来获取resourceCount
-> $resourceCounts[$row['primary_function']]
echo "<tr><td>". $row['pf_id'] ."</td><td>". $row['primary_function'] ."</td><td>". $resourceCounts[$row['primary_function']] ."</td></td>";
要获得最终的总计,请创建一个计数器var并将该值添加到其中-
$total = 0;
....
// add the value in the loop
$total += $resourceCounts[$row['primary_function']];
....