in reply to Re^5: How to read multiple tables into arrays
in thread How to read multiple tables into arrays

I can't do it because the first dbh is not closed. I come up with a not so bright way to do it using fetchrow_array(), so now I have two arrays. One will hold an array of colleges while I query each department in the college. It doesn't look gracious, so I will take suggestions for improvement. Thanks a bunch.

my(@colleges)=();
while (my @ary = $mysth->fetchrow_array()){
push(@colleges, @ary); # @ary is a reference
}
$mysth->finish();

$i = 0;
$j = 0;
foreach(@college){
print "colleges: ", @{colleges->$i}, "\n"; $myQuery = "select d.departmentName from Colleges c join Departments d on c.college_id=d.college_id where c.id=$j";
$j++;
$deptsth = &exeQuery($mydbh, $myQuery);
while (my @ary = $deptsth->fetchrow_array())
{ push(@departments, @ary); # @ary is a reference
print "departments: ", @{departments->$j}, "\n";
$i++; }
}
  • Comment on Re^6: How to read multiple tables into arrays

Replies are listed 'Best First'.
Re^7: How to read multiple tables into arrays
by eric256 (Parson) on Nov 11, 2008 at 05:08 UTC

    Please Please Please put code tags around that code. It will make it actually readable. Then include enough code that we can actually look for improvements. Never include variables in SQL unless you have to. Use bind variables (the DBI docs have tons on this, use ? in the query and then you supply the data while running the query. I also don't know what exeQuery is but you probably don't need the & in front of it, and i would venture to bet you don't need that function at all.


    ___________
    Eric Hodges