Categories > TinyButStrong general >

Add record count with grouping

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Gustaf
Date: 2007-04-08
Time: 16:48

Add record count with grouping

Hello.
On the example with groupings, on the example page. Can I print the record count for the country headgroup. So United State will have 1 and France will have record count nbr 2??
I hope you understand what I mean.
By: sheepy
Date: 2007-04-10
Time: 09:19

Re: Add record count with grouping

I fear that unless Aggregate plug-in is updated, you can only separate the country into two merges to do that.  If you have more countries, you can do it with a loop.
By: TomH
Date: 2007-04-10
Time: 15:21

Re: Add record count with grouping

ALternatively, it is easy enough to use TBS nice "ondata" capability...

The following alterations to the example you reference are tested.

The php code needs to be altered as follows...
$country_cnt = 1;
$country = "ZZZZ";

$TBS->MergeBlock('blk_res',$result) ;
$TBS->Show() ;

function ev_cnt($BlockName,&$CurrRec,$RecNum){

global $country_cnt;
global $country;

  if($CurrRec['country'] != $country){
    $CurrRec['country_cnt'] = $country_cnt;
  $country_cnt += 1;
    }
    $country = $CurrRec['country'];
}

And the template as follows...
        <tr>
          <td width="20" bgcolor="#CFE7CF">Country#&#160;[blk_res.country_cnt]&#160; </td>
          <td colspan="4" bgcolor="#CFE7CF" class="title-section">
                            [blk_res.country;block=tr;headergrp=country;ondata=ev_cnt]
                    </td>
        </tr>

Hope that helps a little,
TomH