You're going to have to collect the data before printing if you want it the way you describe (1-200, 201-400, 401-600). That is, since it's just ID and district, store everything into a hash, then print out from there.:
$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";
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.