【发布时间】:2021-03-24 06:33:16
【问题描述】:
我如何显示这个查询结果:
从 MySQL 到网页,就像这样:
我只想显示计数。我确实通过 PHP 运行了相同的查询,但它返回“2”。 PHP代码如下
<?php
//Connection for database
$conn = mysqli_connect("localhost", "root", "aaaaa", "db");
$query = "SELECT `gender`,COUNT(`gender`) FROM `reg` GROUP BY `gender`";
$result = mysqli_query($conn, $query);
if ($result)
{
// it return number of rows in the table.
$row = mysqli_num_rows($result);
if ($row)
{
printf("" . $row);
}
// close the result.
mysqli_free_result($result);
}
// Connection close
mysqli_close($conn);
?>
请注意,我已经完成了像 one 这样的其他答案,但我无法真正找到解决方法,我只希望值计数而不是表中所有行的总数,例如算上“男性”。
【问题讨论】: