Hi Monks, Not sure how to approach the following issue. I am retrieving values from a DB using fetchrow. I am pushing the values that are being returned into an array. I will then use the values from this array to issue another query to a different DB. The code looks something like this:

my $queryID = "select id, name from studentTable"; my $sth_queryID = $dbh->prepare($queryID); $sth_queryID->execute(); my @studentInfo; while (my @row = $sth_queryID->fetchrow){ push @studentInfo, @row; } $sth_queryID->finish;

@studentInfo will look something like this: @studentInfo = ("001","John","002","Mary","003","Tom") Now, I want to use each id (each of the odd indices within @studentInfo) to issue another query. I will also need to use the corresponding name of that id to insert as a row of a HTML table. So, the code might resemble the following:

foreach (@studentInfo_with_an_odd_index){ my $studentID = $_; my $queryGrade = "select id from grades where id = '$studentID' and grade = 'A'"; $my sth_queryGrade->prepare($queryGrade); $sth_queryGrade->execute(); while (my @g = $sth_queryGrade->fetchrow){ print "<TR>"; print "<TD>$g[0]</TD>"; print "<TD>$student_name_for_this_id</TD>"; print "</TR>"; } } $sth_queryGrade->finish; $dbh->disconnect;
Any ideas on how I can find @studentInfo_with_an_odd_index and $student_name_for_this_id from the above code? Thanks in advance for your help monks.

In reply to Find odd/even elements of array by perlPractioner

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.