以下是连接数据库并检索结果并显示在表格中的代码。
<?
$conn = mysqli_connect("localhost", "root","root", "test");
$query="SELECT `from_email`, COUNT(*) AS emailCount FROM `user_log` GROUP BY `from_email` ORDER BY COUNT(*) DESC";
$result = mysqli_query($conn, $query);
if ($result) {
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH))
{
$table[] = $row;
}
}
?>
<table border="1">
<tr>
<td width="200">From Email</td>
<td width="50">Count</td>
</tr>
<?
if($table){
for($i=0;$i<count($table);$i++){
?>
<tr>
<td><?=htmlentities($table[$i]["from_email"])?> </td>
<td><?=htmlentities($table[$i]["emailCount"])?> </td>
</tr>
<?
}
}
?>
</table>