我正在尝试计算数据库中提及主题标签的次数。因此,第一个 while 是获取所有主题标签,第二个是在另一个内部,同时计算主题标签被提及的次数。但问题是数字不正确,它只是显示 1,2,3,4,5.. 等,当有两次提到的主题标签时,它显示的是 3+4。
我该如何解决这个问题?
$i = 0;
$popular_hashtags_query = mysql_query("SELECT * FROM " . $dbPrefix . "hashtags WHERE status=1");
while ($popular_hashtags = mysql_fetch_array($popular_hashtags_query)) {
echo "<div class='hashtag_label'><a data-hover='";
$count_hashtags_query = mysql_query("SELECT * FROM " . $dbPrefix . "hashtags WHERE status=1 AND hashtag='" . $popular_hashtags['hashtag'] . "'");
while ($count_hashtags = mysql_fetch_array($count_hashtags_query)) {
$i++;
echo $i;
}
echo "'><span>#".$popular_hashtags['hashtag'] . "</span></a></div>";
}