如何在php的HTML表中显示MySQL COUNT()查询结果。
我使用了以下查询:
select name, count(*) from contacts group by 1 having count(*) > 1;
答案 0 :(得分:0)
遵循以下示例:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "select name, count(*) as total from contacts group by 1 having count(*) > 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) { ?>
<table style="width:100%">
<tr>
<th>Name</th>
<th>Total</th>
</tr>
<?php while($row = $result->fetch_assoc()) { ?>
<tr>
<td><?=$row['name'];?></td>
<td><?=$row['total'];?></td>
</tr>
<?php } ?>
</table>
<?php } else { echo "0 results"; } ?>