Forums

Getting a count of the number of records within a group

darrenhallinan 22 Nov, 2015
Hi Folks

So I hit a wall here!

Ill explain what I am doing as this might help others

I have a system running where we are keeping track of stock, (mainly phones and stuff)

Its working well over all, but we need to be able to print a stock sheet where we know at a glance the number of each item we have in stock.

So I created a CC and using the table layout and using group I have exactly what we need (see attachment) except for one thing, The quantity of each item!!!

I have used the group function to group the records using brand, model, colour etc but I can not find a working example of how to count the records in each group and display the count in the row.

Anyone have any ideas?

Thanks
GreyHead 23 Nov, 2015
Hi darrenhallinan,

I can't see a built-in way to do this - you can add a COUNT(column_name) to the fields list but you can't set the AS so it may break other values you need.

Possibly you can add Custom PHP either in the Header or in each row to query the table and get the value you need - far from ideal but could be made to work.

Bob
GreyHead 03 Dec, 2015
Hi darrenhallinan,

Sorry for the delay, there have been couple of similar threads referenced recently (see here and here ) and this one slipped through the cracks :-(

There are some problems with the model ids - CC messes up the quotes at the moment. If you don't need these then I have got this code to work in the Fields box
<?php
return array(
  "COUNT(id)" => "content.num",
  title
);
?>
This creates a MySQL query like this
SELECT COUNT(`content`.`id`) AS `content.num`, `content`.`title` AS `content.title` FROM `c2uzj_content` AS `content`


Does this solve your problem?

Bob
This topic is locked and no more replies can be posted.