How Do You Group And Get Count Of Similar Items.

I am having problem wrapping my head around how to do this.

I would like help with grouping similar items and getting the count if there is a similar item.

Here is the original way I was doing it but I was requested to do it like the picture (right side, the left side is what it currently looks like) and I just can’t wrap my head around it.


$current_case_id = $model->case_id;

$current_id= $model->id;

$criteria = new CDbCriteria();

$criteria->condition = 'case_id =:current_id AND!=:id';

$criteria->params = array(':current_id'=>$current_case_id, ':id'=>$current_id);				

$criteria->with = array('product');

$criteria->together = true;

$asset =  Asset::model()->findAllByAttributes(array() , $criteria);


foreach($asset as $asset) {

	echo CHtml::link($asset->product->model, array('../equipment/asset/view', 'id'=>$asset->id)')).'<hr>';


; ?>



Thank you