duanchouyi6730 2013-11-25 12:10
浏览 16
已采纳

使用PHP在SQL列中输出不同的值

I have a table with two collumns (shortened), NAME and CATEGORY.

I want to output the number of distinct categorys. For an examle: Sport : 5 , Houses : 10.

I use this one:

$test = mysqli_query($con,"SELECT category, COUNT(category) as count FROM tablename GROUP BY category ORDER BY count DESC");

This work then I run the code in SQL Shell, but I have no clue on how to output it in PHP. I have searced Google up and down without any successfull solution.

Any help?

I want to output it in a table format.

EDIT: Here is my full code: (tablename is changed, and $con is removed)

$test = mysqli_query($con,"SELECT DISTINCT lkategori, COUNT(lkategori) as count FROM tablename GROUP BY lkategori ORDER BY count DESC");

while($row = mysql_fetch_array($test)) {
    echo $row['lkategori'] . ":" . $row['count'];
    die("test");
}       
  • 写回答

2条回答 默认 最新

  • douda5227 2013-11-25 12:51
    关注

    use this

    while($row = mysqli_fetch_array($test)) {
        echo $row['lkategori'] . ":" . $row['count'];
        die("test");
    } 
    Thanks 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置