根据Group Id计算PHP中SQL列的平均值并显示在HTML页面上,可以通过以下步骤实现:
$sql = "SELECT group_id, AVG(value) AS average FROM my_table GROUP BY group_id";
$averages = array();
while ($row = mysqli_fetch_assoc($result)) {
$group_id = $row['group_id'];
$average = $row['average'];
$averages[$group_id] = $average;
}
<table>
<tr>
<th>Group Id</th>
<th>Average</th>
</tr>
<?php foreach ($averages as $group_id => $average): ?>
<tr>
<td><?php echo $group_id; ?></td>
<td><?php echo $average; ?></td>
</tr>
<?php endforeach; ?>
</table>
这样,你就可以根据Group Id计算PHP中SQL列的平均值,并将结果显示在HTML页面上了。
腾讯云相关产品推荐:
领取专属 10元无门槛券
手把手带您无忧上云