当我算作计数时,如何获得?

时间:2018-06-24 05:18:07

标签: php mariadb

我想知道总计数器 共有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 个答案:

答案 0 :(得分: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";