做了一些edits--
我WOU ld建议采取两种不同的行动,以使不熟悉该语言的人更容易。你可以试试
select pollComment ,count(*) as count from students group by pollComment
这将允许你得到每个ID的数量,如果这是你想要的。如果您只想获得单个ID的计数,请添加WHERE子句。
select pollComment ,count(*) as count from students group by pollComment where pollid='$pollid';
然后,你可以像你正试图与你的第二个查询更新。
这里是你在找什么作为一个整体,我相信
<?php
$query = "select pollComment ,count(*) as count from polls where pollid='$pollid' group by pollComment ;"
if ($result = mysqli_query($conn, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result))
{
$count = $row['count'];
$update = "UPDATE polls SET PollCommentCount = '$count' WHERE id = '$pollid'";
if ($result = mysqli_query($conn, $update)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
}}
}
/* free result set */
mysqli_free_result($result);
}
?>
你尝试过什么?在MySQL中有一个名为'count'的函数,不知道为什么PHP标记已被添加,但我已投票删除它。 – IsThisJavascript
显示您尝试过的查询的示例。给我们一些东西来帮助你。 –
@RobertDickey,我已经添加了我试过的代码。 – JRK