Hello,

I want to output the contents of a DB table into an HTML table.

The DB table has 600 rows.
I'de like to have the output be formatted as an HTML table with 3 columns of 200 rows each.

<tr> <td>$indexs0-200</td> <td>$indexs201-400</td> <td>$indexs401-600</td> </tr>

I've gotten as far as outputting one long column, but this is as far as I got.
I'm thinking I need to do a while loop with a for statement in it but I'm not really sure how to do it.
Heres my code so far: Thanks - Donzo

#!/usr/bin/perl -w use DBI; use strict; use CGI; my $q; $q = new CGI; print $q->header, $q->start_html("District List"); my $dbh = DBI->connect("DBI:ODBC:PM_Pages","","") or die "Cannot conne +ct: " . $DBI::errstr; my $sql = "select District,DIST from Districts"; my $sth = $dbh->prepare($sql) or die "Cannot prepare: " . $dbh->errstr +(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); my $district; my $ID; while (($district,$ID) = $sth->fetchrow_array) { print ("a href=\"$ID\">$district</a> <br> "); } $sth->finish(); $dbh->disconnect; print $q->end_html;

In reply to DBI output in 3 columns by Donzo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.