-1

我的文章上有标签,我想为它制作一个标签云,但我不知道该怎么做

你能帮忙的话,我会很高兴

    $result = mysql_query("SELECT *, COUNT(login_news.tag) FROM login_tags
                        LEFT JOIN login_news ON login_tags.tag_id = login_news.tag  GROUP BY tag_id
                           ");


  while($row = mysql_fetch_array($result)){



        echo $row['name'];
        echo "<br>";
        echo $row['COUNT(login_news.tag)'];
        echo "<br>";

        }

这是我能猜到的

4

2 回答 2

0

试试这个,将mysql别名添加到count(login_news.tag),方法AS是在php中添加并调用它作为$result['AliasName']

$result = mysql_query("SELECT *, COUNT(login_news.tag) AS tag_count FROM login_tags
                            LEFT JOIN login_news ON login_tags.tag_id = login_news.tag  GROUP BY tag_id
                               ");


      while($row = mysql_fetch_array($result)){
            echo $row['name'];
            echo "<br>";
            echo $row['tag_count'];
            echo "<br>";

      }
于 2013-04-28T03:16:16.160 回答
0

我就是这样做的-_-

 $result = mysql_query("SELECT tag_id, tag_name, COUNT(login_news.tag) AS tag_count FROM login_tags
    INNER JOIN login_news ON login_tags.tag_id = login_news.tag  GROUP BY tag_name
                                   ");


          while($row = mysql_fetch_array($result)){

          if($row['tag_count'] > 5){

          $fontsize = "11";

          }

          if ($row['tag_count'] > 15){

          $fontsize = "13";

          }

          if ($row['tag_count'] > 30){

          $fontsize = "15";

          }

          ?>


          <li style="font-size:<?php echo $fontsize?>!important;"><a href="/index.html?tag=<? echo $row['tag_id']; ?>" title="<? echo $row['tag_count']; ?> სიახლე"><? echo $row['tag_name']; ?></a> </li>


        <?

            }



    ?>
于 2013-04-28T04:58:18.113 回答