dear monks, I cant make a foreach loop iterate over a list more than once. I pull the db data fine and join it into a list. It fetches the first row of data and then terminates??? this is what i have:
#!perl -wT use CGI; use CGI::Carp qw ( fatalsToBrowser ); use DBI; use strict; my $q = new CGI; my %attr = (RaiseError=>1, PrintError=>1); my @field_name = qw ( property_id address_1 address_2 county city z +ip description status bedroom bathroom ); my @field_desc = qw ( ID Address Address County City PostalCode Des +cription Status Bedrooms Bathrooms ); my $dbh = DBI->connect("dbi:mysqlPP:$db:$server", $username, $passw +ord,{RaiseError =>1}); print $q->header("text/html"), $q->start_html(-title=>"Lettingsetc.co.uk | Admin | Edit", -sr +c=>"/mycss.css"), $q->h1("Lettingsetc.co.uk"), $q->h4("Administration>Edit property details!"); my $field_list = join (",", @field_name); print <<HTML; <H1>All Properties</H1> <TABLE BORDER=1> <TR> HTML my $SQL = "SELECT $field_list FROM property"; my $i; foreach $i(@field_desc) { print "<TH>$i</TH>\n"; } print qq `</TR><TR>`; my $sth = $dbh->prepare($SQL); $sth->execute() or die $dbh->errstr; my $row; foreach $row( $sth->fetchrow_array)# while more rows fetch next one { print "<TD>$row</TD>\n";# print row data in HTML } print "</TR></TABLE>"; print $q->end_html; $dbh->disconnect() or die $dbh->errstr;
Thanks

In reply to foreach loop by r_mehmed

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.