目前此查询仅从数据库输出一个结果,我需要它按标签发布的次数显示前十个结果。
因此,如果#stackoverflow在帖子中被标记了8次而stackexchange在帖子6中被标记,那么我将拥有
1.Stackoverflow
8个帖子
2.stackexchange
6个帖子
等最多十个结果。目前我只有一个返回的标签结果,我有2个帖子使用相同的标签,但它只显示一个记录,并在显示一个记录和2个帖子时说1个帖子..还有多个记录,如果有多个不同我的数据库中的#标签。
我已添加到我的标签,它清楚我的代码中没有while循环,我想知道它是否缺少这个!
<?
$chantj = mysqli_query($mysqli, $callj);
$num = mysqli_num_rows($chantj);
$calltrendingj = "SELECT streamitem_content,streamitem_id,
COUNT(streamitem_content) AS total
FROM streamdata
WHERE streamitem_content LIKE '%#%'
GROUP BY streamitem_content
ORDER BY total DESC LIMIT 10";
$chanttrendingj = mysqli_query($mysqli, $calltrendingj);
if (!$chanttrendingj) {
printf("Error: %s\n", mysqli_error($mysqli));
exit();
}
$numtrendingj = mysqli_num_rows($chanttrendingj);
for($i=1; $numrowscountj = mysqli_fetch_array($chanttrendingj); $i++)
{
$conttrend = mysqli_real_escape_string($mysqli,stripslashes($numrowscountj['streamitem_content']));
$autoembedtrend = new AutoEmbed();
$conttrend = $autoembedtrend->parse($conttrend);
$regextrend = "/#+([a-zA-Z0-9_]+)/";
$conttrend = preg_replace($regextrend, '<a href="hash.php?tag=$1">$0</a>', $conttrend);
$conttrend=substr($conttrend, 0, strrpos($conttrend, ' '));
$conttrend = str_replace('#', '', $conttrend);
?>
Trending<br><hr>
<h2><? echo $conttrend; ?></h2>
<? if($numtrendingj==1){?>
<h5><? echo $numtrendingj?> Post</h5>
<? }else if($numtrendingj>1){ ?>
<h5><? echo $numtrendingj ?> Posts</h5>
<? } ?>
<br>
<? } ?>