计算php中具有相同ID的行 [英] Count the rows with same ID in php
本文介绍了计算php中具有相同ID的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试计算具有相同 ID 的行
|curs_code|cursistnr|标记|已付费|C# 20 6 50菲律宾比索 25 8 100C# 8 7 100
输出需要
C#,2 次p>
我试过了
$sql = "SELECT count(curs_code) as 'count_of_curs' FROM cursus where curs_code='$id'";$query = $magazijn->query($sql);返回 $query->fetchAll());
但是给了我这个输出:
C#数组(大小=1)0 =>数组(大小=2)'count_of_curs' =>字符串1"(长度=1)0 =>字符串1"(长度=1)PHP数组(大小=1)0 =>数组(大小=2)'count_of_curs' =>字符串1"(长度=1)0 =>字符串1"(长度=1)
您对此有何看法?
解决方案
SELECT curs_code, count(*) as 'count_of_curs' FROM cursus where curs_code='$id' group by curs_code
如果需要整个列表,请删除 where.
I'm trying to count the rows with the same id
|curs_code|cursistnr|Mark|Payed|
C# 20 6 50
PHP 25 8 100
C# 8 7 100
the output needs to be
C#, 2times
I've tried
$sql = "SELECT count(curs_code) as 'count_of_curs' FROM cursus where curs_code='$id'";
$query = $magazijn->query($sql);
return $query->fetchAll());
but gives me this output:
C#
array (size=1)
0 =>
array (size=2)
'count_of_curs' => string '1' (length=1)
0 => string '1' (length=1)
PHP
array (size=1)
0 =>
array (size=2)
'count_of_curs' => string '1' (length=1)
0 => string '1' (length=1)
your thought about this?
解决方案
SELECT curs_code, count(*) as 'count_of_curs' FROM cursus where curs_code='$id' group by curs_code
Remove the where if you want the entire list.
这篇关于计算php中具有相同ID的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文