2013-10-20 79 views
0

選擇什麼是錯我的代碼返回其0的MySQL通過過濾

  $query = "SELECT cid, COUNT(cid) FROM topic_reply WHERE cid='$forum_id'";  
     $result = mysql_query($query) or die(mysql_error());  
     while($row = mysql_fetch_array($result)){ 
      echo "There are ". $row['COUNT(cid)'] ." ". $row['cid'] ." items."; 
      echo "<br />"; 
     } 

我嘗試所有可能的代碼,以顯示其returng 0的結果..但如果我刪除了WHERE過濾其返回所有行發生了什麼?嘿嘿

回答

1

我不知道你要完成的任務,但我認爲這可能是一個特定的CID的計數:

$query = "SELECT cid, COUNT(cid) FROM topic_reply WHERE cid='$forum_id' GROUP BY cid"; 
+0

$論壇=請求mysql_query(「SELECT * FROM論壇其中pid ='$ CAT_ID'「); while($ forumrow = mysql_fetch_array($ forum)) { // code here $ threadcount = mysql_query(「SELECT * FROM topics WHERE parent ='$ forum_id'」); $ thread_count_rows = mysql_num_rows($ threadcount); ($ threadrow = mysql_fetch_array($ threadcount)) { $ parent_id = $ threadrow ['id']; \t \t \t \t } \t \t //這裏 更多的代碼下面繼續 – user2879926

+0

$查詢= 「選擇CID,COUNT(CID)FROM topic_reply WHERE CID = '$ forum_id' GROUP BY CID」; $ result = mysql_query($ query)或die(mysql_error()); \t while($ row = mysql_fetch_array($ result)){\t $ temp1 = $ row ['COUNT(cid)']; \t \t if($ temp1 == 1){echo''; } elseif($ temp1> = 10){echo''; } //依此類推} } – user2879926

+0

@ user2879926,是否有效? –