gpt4 book ai didi

php - 仅显示 MySQL 列值计数

转载 作者:行者123 更新时间:2023-12-05 04:55:42 26 4
gpt4 key购买 nike

<分区>

如何显示这个查询结果:

result

从MySQL到网页,就像这样:

this

我只想显示计数。我确实通过 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但我真的找不到办法,我只希望计算值而不是表中所有行的总数,例如算作“男性”。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com