文章标签云php mysql

时间:2013-04-28 03:03:57

标签: php mysql

我的文章上有标签,我想为它制作标签云,但我无法弄清楚如何做到这一点

任何帮助都会很好

    $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>";

        }

这和我猜的一样多

2 个答案:

答案 0 :(得分:0)

试试这个,通过添加AS将mysql别名添加到count(login_news.tag)并在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>";

      }

答案 1 :(得分: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>


        <?

            }



    ?>