push (@row, Tr( td({-width=>"10%"},u(b("Bottles Remaining"))), td({-width=>"*"},u(b("Wine"))) )); while (my $ref = $sth->fetchrow_hashref()) { my $country = escapeHTML($ref->{'country'}); if ($country ne $oldcountry) { push (@row, Tr(td({class=>"regioncount"}," $regioncount Total for region"))) unless $regioncount == 0; # skip first pass push (@row, Tr({class=>"countrycount"},td("$countrycount Total for country"))) unless $countrycount == 0; # skip first pass push (@row, Tr(td({class=>"countryheader"},$country))); $countrycount = 0; $oldregion = "bar"; # clear region when country changes } $oldcountry = $country; my $region = $ref->{'region'} ? escapeHTML($ref->{'region'}) : "Other"; if ($region ne $oldregion) { push (@row, Tr(td({class=>"regioncount"}," $regioncount Total for region"))) unless ($regioncount == 0) or ($countrycount == 0); # skip first pass push (@row, Tr(td({class=>"regionheader"},$region))); $regioncount = 0; } $oldregion = $region; $regioncount += $ref->{'number_left'}; $countrycount += $ref->{'number_left'}; $totalcount += $ref->{'number_left'}; my $wine_name = a({-href=>"wine_display.cgi?id=$ref->{id}"}, escapeHTML($ref->{'wine_name'})); push (@row, Tr({-class=>"$rowcolor"}, td({-class=>"body"},$ref->{'number_left'}), td($wine_name) )); $rowcolor = ($rowcolor eq "lightrow" ? "darkrow" : "lightrow"); } push (@row, Tr({class=>"regioncount"},td("$regioncount Total for region"))); push (@row, Tr({class=>"countrycount"},td("$countrycount Total for country"))); push (@row, Tr({class=>"totalcount"},td("$totalcount Total in cellar"))); print table({-width=>"95%", -cellspacing=>"0"},@row);