XF 2.2 how to group and count?

Robert9

Well-known member
table

id1|id2 with unique(id1-id2)
1 | 2
1 | 3
1 | 4
2 | 2
2 | 5
2 | 6
3 | 7

i have an array with id1s
i could, but dont want:

foreach arrayId1 as $key
{
$result => $repo->find id1/id2 where id1=$key
$result->count()

=> count(arrayid1) queries?

instead i can try
$result => $repo->find id1/id2 where id1 in $array{id1} ->group by id1

foreach $result as $key
{
$counter{$key} = $result->count()

better way and 1 query?
 
Back
Top Bottom