Ok, well basically, I think you just wanted to move the print that prints the header out of the loop.. I did that and then got a bit carried away..
Now, I have to add, I've never used CGI.pm to create HTML so whether those print statements are correct or not is for you to decifer. It looks to me as if you may actually be starting a table for the headers and then starting a new table for each of the rows but the rest should be ok. **This code is totally untested..
You will need to change the names of the fields to the field names in you database table in the 2 parts of the script that refer to them.
# we've split the data from presentation as much as we can
# so we start by getting the customer data which is returned
# by 'get_customer' as an array of hash references.
my $customer = get_customer($customer_id);
# print the table header
print table ({-border => 0},
Tr ({-align => "CENTER", -valign=>"TOP", -BGCOLOR=>"silver"
+, -style=>"font-family: verdana; font-size: 10pt;"},
th ({-width=>"50"},("Customer ID")),
th ({-width=>"50"},("Carrier")),
th ({-width=>"90"},("Tracking Number"))
));
# print the rows of customer data
# $customer is a reference to an array, so we dereference that
# with '@' so we can loop through it's values, assigning them
# to $row, one at a time. $row is now a hash reference so we
# can derefence each key/value using the 'arrow' "$row->{key}".
foreach my $row (@$customer){
print table ({-border => 0},
Tr ({-valign=>"center", -style=>"font-family: verdana; font
+-size: 10pt;"},
# **** these 'keys' will need to be changed to the names of your datab
+ase fields. ****
td ($row->{customer_number}),
td ($row->{carrier}),
td ($row->{tracking_number})
));
}
print start_form (-action => "http://wwwapps.ups.com/tracking/tracking
+.cgi", -method => "POST"),
table (
Tr (
td ("UPS Tracking Number:"),
td (textfield (-name => "tracknum"))
),
),
submit (-name => "choice", -value => "Track"),
end_form ();
sub get_customer{
my ($customer_id) = @_;
my $dbh = WebDB::connect();
# **** change "customer_number, carrier, tracking_number" to the na
+mes of your database fields. ****
my $sth = $dbh->prepare ("SELECT customer_number, carrier, tracking_
+number FROM Shipments WHERE customer_id = ?");
$sth->execute($customer_id);
# push each result row into @customer
while (my $track_ref = $sth->fetchrow_hashref()){
push(@customer, $track_ref);
}
# return @customer as an array reference
return(\@customer);
}
cheers,
J |