如何显示这个查询结果:
从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但我真的找不到办法,我只希望计算值而不是表中所有行的总数,例如算作“男性”。