2013-04-28 63 views
-1

我有我的文章標籤,我想爲它的標籤雲,但我不能弄清楚如何做到這一點文章標籤雲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>"; 

     } 

這是像我猜測的

回答

0

試試這個,加入AS添加MySQL別名來算(login_news.tag),並把它稱爲在PHP作爲$結果[「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>"; 

     } 
+0

由於多數民衆贊成有助於一點點... – 2013-04-28 04:57:49

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> 


     <? 

      } 



    ?>