Php 列出前十个标签

Php 列出前十个标签,php,foreach,while-loop,preg-replace,Php,Foreach,While Loop,Preg Replace,目前,这个查询只从数据库中输出一个结果,我需要它按标签发布的次数显示前十个结果 所以如果#stackoverflow在一篇文章中被标记了8次,而stackexchange在第6篇文章中被标记,那么我会 1.堆垛溢出 8个员额 2.外汇 6个员额 以此类推,结果多达10个。目前,我只有一个返回的hashtag结果,我有两篇文章有相同的hashtag,但它只显示一条记录,当它显示一条记录和两篇文章时,会显示1篇文章。。如果我的数据库中有多个不同的hashtag,那么也会有多个记录 我已经将while

目前,这个查询只从数据库中输出一个结果,我需要它按标签发布的次数显示前十个结果

所以如果#stackoverflow在一篇文章中被标记了8次,而stackexchange在第6篇文章中被标记,那么我会

1.堆垛溢出

8个员额

2.外汇

6个员额

以此类推,结果多达10个。目前,我只有一个返回的hashtag结果,我有两篇文章有相同的hashtag,但它只显示一条记录,当它显示一条记录和两篇文章时,会显示1篇文章。。如果我的数据库中有多个不同的hashtag,那么也会有多个记录

我已经将while添加到我的标记中,很明显我的代码中没有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>
  <? }  ?>

按“%”分组
这太奇怪了。你认为你想按列分组,并且怀疑你有一个类似名称的列,是吗?添加
ini\u集('display\u errors',1);ini_集(“日志错误”,1);错误报告(E_全部);mysqli_报告(mysqli_报告错误| mysqli_报告严格)
到脚本顶部并查看错误流程您可以在FlipSide上ping我您可能希望在mysql控制台中检查这些查询的结果…因此,假设我在两篇单独的文章中向数据库发布了两次
#testing
,那么我将如何对它们进行分组,以便它能够输出
testing 2 posts