我试图为select选项中的每个选项创建一个计数,下面是我这样做的功能但我意识到所有它确实计算了有多少用户没有做出选择。我想要计算在数据库中选择每个选项的次数,有人有任何建议吗?
function teamCount($mysqli){
$count = "SELECT count(selection) FROM users GROUP BY selection HAVING count(*) > 1";
$result = $mysqli->query($count);
$rows = mysqli_fetch_row($result);
echo '('.$rows[0].')';
}
下面是表格模拟:
username selection
..... Buffalo bills
..... Baltimore ravens
我希望计数通过选择列并计算数据库中的重复条目,以便它在前端显示:
Buffalo Bills [1]
Baltimore Ravens [1]
答案 0 :(得分:0)
$count = "SELECT selection, count(*) FROM users GROUP BY selection HAVING count(*) > 1";
你可以试试这个。