The code I am using requires foreknowledge of the amount of results to be outtputted.
There's a bunch of ways you could do this, but they mostly depend on how you'll be outputting your data. If you're just listing what you got out of the database you could just do this
while(my $rr = $sth->fetchrow_hashref()) { print "$_: $rr->{$_}\n" for keys %$rr; }
Or if you're not too concerned about the field names you could just print out all the values like so
while(my @rows = $sth->fetchrow_array()) { print "Values: @rows\n"; }
Or if you want a list of enumerated the values
while(my @rows = $sth->fetchrow_array()) { print "$_: $rows\n" for @rows; }
So as you can see you have plenty of options. Personally I'd recommend using the fetchrow_hashref() method as the brain maps better to names than sequences. See the DBI docs for more info on the methods mentioned above.
HTH

_________
broquaint


In reply to Re: Re: Creating Dynamic SQL statements using arrays by broquaint
in thread Creating Dynamic SQL statements using arrays by johnirl

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.