+<h2>Offers to <% uc $bs |h %> <% $commodname |h %></h2>
+
+<table>
+<tr>
+<th colspan=3>
+<th colspan=2>Prices
+<th colspan=3>Quantities available
+<tr>
+<th>Archipelago
+<th>Island
+<th>Unique best stall
+<th>Best
+<th>Median
+<th>At best
+<th>Within 10%
+<th>Total
+</tr>
+% $islands->execute($commodid);
+% my $island;
+% while ($island= $islands->fetchrow_hashref) {
+% my $islandid= $island->{'islandid'};
+% $offers->execute($commodid, $islandid);
+% my ($offer, $bestprice, $marginal, @beststalls);
+% my $tqty= $island->{'tqty'};
+% my $cqty= '';
+% my $bestqty= '';
+% my $approxqty= '';
+% my $median= '-';
+% while ($offer= $offers->fetchrow_hashref) {
+% my $price= $offer->{'price'};
+% my $qty= $offer->{'qty'};
+% length $bestqty or $bestprice= $price;
+% if ($price == $bestprice) {
+% $bestqty += $qty;
+% push @beststalls, $offer->{'stallname'};
+% }
+% $cqty += $qty;
+% if ($cqty*2 >= $tqty && $median eq '-') {
+% $median= $price;
+% }
+% if ($bestprice*9 <= $price*10 and
+% $price*10 <= $bestprice*11) {
+% $approxqty += $qty;
+% }
+% }
+% my $nstalls= @beststalls;
+% $cqty == $tqty or die "$bs $cqty $tqty $commodid $islandid ";
+<tr> <td><% $island->{'archipelago'} |h %>
+ <td><% $island->{'islandname'} |h %>
+ <td><% $nstalls==0 ? '-' :
+ $nstalls==1 ? $beststalls[0] : "$nstalls offers" |h %>
+ <td><% length $bestqty ? $bestprice : '-' %>
+ <td><% $median %>
+ <td><% $bestqty %>
+ <td><% $approxqty %>
+ <td><% $cqty %>
+</tr>
+% }
+</table>
+
+<%perl>
+}
+</%perl>