perlPractioner has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Find odd/even elements of array
by CountZero (Bishop) on Oct 09, 2011 at 21:18 UTC | |
Re: Find odd/even elements of array
by keszler (Priest) on Oct 09, 2011 at 21:33 UTC | |
Re: Find odd/even elements of array
by AnomalousMonk (Archbishop) on Oct 09, 2011 at 22:34 UTC | |
Re: Find odd/even elements of array
by johngg (Canon) on Oct 09, 2011 at 21:39 UTC | |
Re: Find odd/even elements of array
by RichardK (Parson) on Oct 09, 2011 at 20:49 UTC | |
Re: Find odd/even elements of array
by choroba (Cardinal) on Oct 09, 2011 at 21:44 UTC | |
Re: Find odd/even elements of array
by dsheroh (Monsignor) on Oct 10, 2011 at 10:34 UTC |
Back to
Seekers of Perl Wisdom