首页 文章

如果算上伯爵,怎么才能得到它? [关闭]

提问于
浏览
-2

我想知道总计数器总共有15个cc_cates . 我想用一个查询找到整个值 .

$result = mysqli_query($connect, "SELECT distinct cc_cate,
                  count(cc_cate)as count
             FROM cc_text
             WHERE id='aaaa'
             group by cc_cate
             order by cc_cate desc"
      ) or die("cate");
for ($i = 0; $t = mysqli_fetch_array($result); $i++) {    
            if ($i == $t['count']) $last = "colspan=7"; 
            echo "$i == $t[count] ,";
    }

1 回答

  • 1

    仍然不完全清楚,但遵循您在评论中指定的内容,我想这两个答案中的一个应该是您正在寻找的:

    // if you just want the number of categories
    
    $result = mysqli_query($connect, "SELECT COUNT(distinct cc_cate) as cnt_cat FROM cc_text WHERE id='aaaa'") or die("cate");
    $row = mysqli_fetch_assoc($result);
    echo "Number of categories = ". $row['cnt_cat'];
    
    
    // if you want to list all categories and count them all 
    
    $result = mysqli_query($connect, "SELECT distinct cc_cate FROM cc_text WHERE id='aaaa'") or die("cate");
    $i=0;
    while ($row = mysqli_fetch_assoc($result)){
        $i++;
        echo "Category $i = ". $row['cc_cate'];
    }
    echo "Total categories = $i";
    

相关问题