What is the following code supposed to do?

foreach $i(0..$#{$rows}) { foreach $j (0..$#{$rows->[$i]} ) { $rows->[$i][$j]; } }

Answer: Each time the code runs I select distinct(id) from table. When I fetch the id's and put them into an array, they are all placed into array index '0'. I want to pass individual id's to the sql statement so I add indexes by the above logic where I iterate through by incrementing $i++.

Have you tried replacing the query results with hardcoded data? Does the program work then as you want it to?

while ($i<=2) { my $placeholder = ":p_$j"; print "$placeholder\n"; my $rd = "$rows->[$i][0]"; print "$rd\n";

Answer: Yes. I can set the rd to equal a specific value and it returns the value result. If the array = ('A01','B88','C88',....'nth'), I want to only select * from table where id = 'A01'; pass 'A01' to email, then 'B88'....then 'C88'....'nth'.

The while loop iterates through the array and changes the index value. The value changes as $i increments. The problem is the sql code only returns data for the first array index. All of the print statements change. All of the emails and spreadsheet data is changed. but only the first array index is populated in the emailed spreadsheets.


In reply to Re^4: SQL query using dynamic array by cocl04
in thread SQL query using dynamic array by cocl04

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.