in reply to DBI output in 3 columns
$sth->execute() or die "Cannot execute: " . $sth->errstr(); my %hash; while ( my( $district, $ID ) = $sth->fetchrow_array ) { $hash{ $district } = $ID; } # A number of ways to do it here, this is the best if you # don't know you have an exact multiple of 3.... my @keys = sort keys %hash; # sort by district my $column=0; print "<TABLE>\n"; while ( my $dis = shift @keys ) { if ( $column == 0 ) { print "<TR>\n"; } print "<TD><A HREF=\"", $hash{ $dis }, "\">", $dis, "</a></TD>"; if ( $column == 2 ) { print "</TR>\n"; $column = 0; } else { $column++; } } # Print trailing TR if needed if ( $column != 0 ) { print "</TD>\n"; } print "</TABLE>\n";
|
|---|