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

So this is the final code I've got, but it doesn't read into college_id as it should be. Thanks! my (@colleges) = ();
while (my @ary = $mysth->fetchrow_array()){
push(@colleges, @ary); # @ary is a reference
$i++;
}
$mysth->finish();
$college_id;
$i = 0;
foreach(@colleges){
# print "colleges: ", @{colleges->$i},"\n";
$college_id=@{colleges->$i};
$i++;
print "college id: ", $college_id, "\n";
$myQuery = "select d.departmentName from Colleges c join Departments d on c.college_id=d.college_id where c.college_id='$college_id'";
$deptsth = &exeQuery($mydbh, $myQuery);
$j=0;
while (my @ary = $deptsth->fetchrow_array()){
push(@departments, @ary); # @ary is a reference
print "departments: ", @{departments->$j}, "\n";
$j++;
}
}
  • Comment on Re^2: How to read multiple tables into arrays

Replies are listed 'Best First'.
Re^3: How to read multiple tables into arrays
by graff (Chancellor) on Nov 11, 2008 at 02:18 UTC
    • You left out the initial query that was used to create "$mysth", so we don't really know what is being pushed onto "@colleges"

    • You still haven't learned about using <code> tags; this is getting in the way, and it's getting tiresome.

    • You call a function named "exeQuery", but you give us no clue what this is, or what it does (if anything) besides "prepare" and "execute".

    • You haven't told us what else you plan to do besides fetch stuff from the database and print things to show that the queries are working; the nature of the "real" task will have an impact on how you set up the query and how you handle the data returned by the query.

    Start using <code> tags (edit the posts you've already made to include these tags), tell us more about what you are really trying to accomplish (beyond just getting stuff out of a set of tables), and try to show some evidence that you are able to learn from the advice you are getting (so we know that we aren't wasting our time trying to help you).