Ward P Fontenot wrote:
Hi, I have a working DBI::Oracle script that I am now trying to get
CGI.pm to HTML-ize the output of, My problem is in the table statement
how can I get the output of the while statement to be in the table? I
have just about beat myself silly trying to figure this out.

SCRIPT:

#!/usr/bin/perl
#
use strict;
use DBI;
use CGI qw(:standard escapeHTML);

#
# Set some environment variables
#
$ENV{ORACLE_HOME} = '/opt/oracle/9i';
my ($count, $dbh, $host, $pass, $port, $r_au, $sql, $sid, $sth, $user,
@row);

#
# my declarations
#
$host = 'host=HOSTNAME';
$pass = 'PASSWORD';
$port = 'port=PORT';
$sid  = 'sid=SID';
$user = 'USER';

$dbh = DBI->connect("dbi:Oracle:$host;$sid;$port", $user, $pass,
                        { RaiseError => 1, AutoCommit => 0}
                        ) || die "Database connection not made:
$DBI::errstr";

$sql = qq{ select r.au_number, count(distinct r.subj_id)
              from t_request r, t_certificate c
              where r.req_status_id=9  and
                (r.req_id=c.req_id) and
                c.cert_status_id=1
              group by au_number };

$sth = $dbh->prepare($sql);
$sth->execute();
$sth->bind_columns(undef, \$r_au, \$count);

print header(), start_html("BEST CertMan results");

print h1("Results"),
        table({-border=>'1', -width=>'20%'},
                Tr({-align=>'LEFT', -VALIGN=>'TOP'},
                        th({-width=>'30%', -bgcolor=>'#CCCCCC'}, "AU"),
                        th({-bgcolor=>'#AAAAAA', -fontcolor=>'#FFFFFF'},
"Certs"),
                ),

        while (@row = $sth->fetchrow_array())
        {
                        Tr( td( [EMAIL PROTECTED] ));
        }

);

$sth->finish();

# Disconnect from Oracle
$dbh->disconnect;

print "<a href=\"../\">Return</a>\n";

print end_html();


I've done things like this myself. You might find the shortcut I used to bind the columns interesting. Here's a sub from a recent project that creates a table within a form.


sub existing_images ($)
{
my $item_id = shift;
my $dbh = new_connect($database, $dbi_user, $dbi_pass);
my $sth = $dbh->prepare("SELECT image_id, image_filename, image_type FROM $image_table WHERE item_id = ? ORDER BY image_type DESC");
$sth->execute($item_id);
my $rows = $sth->rows;
unless ($rows)
{
return h3("No Images currently associated with this item");
}
my @table;
push @table, (
start_form(), hidden(-name=>'item_id', -value=>$item_id),
start_table({-border=>1}), Tr( th("Image Filename"), th("Image Type"), th("Remove Image"))
);


    my ($id, $filename, $type);
    $sth->bind_columns( \($id, $filename, $type) );

while ($sth->fetch)
{
push @table, ( Tr(
td( a({-href=>$filename, -target=>'_new'}, $filename)),
td({-align=>'center'}, $type),
td({-align=>'center'}, checkbox(-name=>'removeimage', -value=>$id, -label=>''))
) );
}


push @table, end_table();
push @table, (
p("Be certain of the images you have selected for deletion; this action is ", b("not undo-able"), "."),
p("Should you wish, you may click the image filenames above to preview each image before making your decision."),
p("Note that this only removes the selected images from the database entry, and does ", b("not"), " delete the files from the directory itself.")
);
push @table, ( p({-align=>'center'}, submit(-name=>'delete', -label=>'Remove Selected Images') ), end_form() );
return @table;
}


then somewhere in the middle of the other html output I need merely do

print existing_images($requested_itemid);

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to