# 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 database 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 names 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); }