#!/usr/bin/perl -w use CGI; use DBI; use strict; use vars qw($dbh); BEGIN { $dbh = DBI->connect("DBI:ODBC:PM_Pages","","", { RaiseError => 1 }); } END { $dbh->disconnect if $dbh; } my $q; $q = new CGI; print $q->header, $q->start_html("District List"), $/; my $sql = "select District, DIST from Districts"; my $sth = $dbh->prepare($sql); $sth->execute(); my $cols = 3; my @rows = @{$sth->fetchall_arrayref}; # my $col_length = POSIX::ceil(@rows / $cols); my $col_length = (@rows - @rows % -$cols) / $cols; print "", $/; for my $row (0 .. $col_length - 1) { print "", $/; for my $col (0 .. $cols - 1) { my $idx = $row + ($col * $col_length); last unless $idx < @rows; printf '', @{$rows[$idx]}[1,0]; print $/; } print "", $/; } print "
%s
", $/; print $q->end_html, $/;