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


In reply to Re: Re: Re: No results from script by edoc
in thread No results from script by b310

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.