smrtalec <[EMAIL PROTECTED]> wrote: : : before I begin thanks for taking the time to help me out.
You're welcome. That's what we are here for. : > print : > header(), : > start_html( 'This page has no title' ), : > gen_table( '%Ave%' ), : > end_html(); : > : > : > sub gen_table { : > : > my $search = shift; : > : > # define table heading : > my @rows = th( [ 'id no.', 'street no.', 'street : name', 'city' ] ); : > : > # load 1 street per row : > push @rows, td( $_ ) foreach @{ query_data( $search ) }; : > : : code wise I follow everything that you do up to the line : above. it seems your doing the same thing however you've : just truncated the code. the script runs however the table : does not print beyond the header. The script you showed the second time use this push: push(@rows,"td([$id,$str_no,$str_name,$city])"); <--- Notice the quotes The message with just the subroutine had this: push(@rows,td([$id,$str_no,$str_name,$city])); Those quotes are making your table appear empty. : unfortunately i'm having some problems writing in a check : to verify the data is imported. could you include the : longer version of the above code that I could understand : a bit more whats happening. Short Answer: foreach my $fields ( @{ query_data( $search ) } ) { push @rows, td( $fields ); } ---------------------------- Long Answer: Let's look at the original lines you had: my $array_ref=query_data('%Ave%'); foreach my $row_array (@$array_ref) { my ($id,$str_no,$str_name,$city) = @$row_array; push(@rows,td([$id,$str_no,$str_name,$city])); } In the 'foreach', @$array_ref is the same as @{ query_data('%Ave%') }. So we can substitute and rid ourselves of $array_ref: foreach my $row_array ( @{ query_data('%Ave%') } ) { my ($id,$str_no,$str_name,$city) = @$row_array; push(@rows,td([$id,$str_no,$str_name,$city])); } @{ query_data('%Ave%') } is an array of arrays, so each item in the top array is a reference to an array. The line: "my ($id,$str_no,$str_name,$city) = @$row_array;" pulls the fields out of the arrayref and then places them back into an array ref on the next line: push(@rows,"td([$id,$str_no,$str_name,$city])"); Since the fields are being pushed onto @row in the same order as they appear in the array ref, there is no need to place them in the fields to begin with. foreach my $row_array ( @{ query_data('%Ave%') } ) { push(@rows, td( $row_array ) ); } Ideally, the table header information should also come from the query_data() routine. If you ever add a field or change field order, everything would be in the same place. The other advantage is that gen_table() can produce the table for results of any query. That eases the script's ability to produce consistent output. sub gen_table { my $search = shift; # load streets my $results = query_data( $search ); # define table heading my @rows = th( shift @$results ); # load one result per row push @rows, td( $_ ) foreach @$results; # produce table return table( { -border => 0, -width => '25%' }, caption( b( 'Wow. I can multiply!' ) ), Tr( [EMAIL PROTECTED] ), ); } sub query_data { my $user_entry = @_; my $dbh = connect_try( 'rowan', '******' ); my $user_quoted = $dbh->quote( $user_entry ); my $sth = $dbh->prepare( qq| SELECT id_pro, str_no_addr, str_name_addr, cit_addr FROM s3a_inglewood_project_info WHERE str_name_addr LIKE $user_quoted; |) or err_trap( 'failed to prepare statement\n' ); $sth->execute or err_trap( 'failed to execute statement\n' ); my $array_ref = $sth->fetchall_arrayref(); # place field names on top <---- I added these two lines unshift @$array_ref, [ 'id no.', 'street no.', 'street name', 'city' ]; $dbh->disconnect or err_trap( 'failed to disconnect at get_date statement\n' ); return $array_ref; } HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>