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

Just build a query that takes the college/department as parameters. Then loop over colleges and departments (from two other queries) returning what you want. Really we can't help you unless you show what your stuck at...unless you want to hire someone? Then you are probably in the wrong place.


___________
Eric Hodges
  • Comment on Re^3: How to read multiple tables into arrays

Replies are listed 'Best First'.
Re^4: How to read multiple tables into arrays
by pinkgladiator (Initiate) on Nov 10, 2008 at 22:22 UTC
    I'd love to hire someone if I was rich. :) Anyway, this is what I attempted to do:
    #$colleges = sth->fetchrow_array();
    #while (my($colleges)=$colsth->fetchrow_array()){
    # print "$colleges \n";
    # $myQuery = "select d.departmentName from Colleges c join Departments d on c.college_id=d.college_id";
    # $deptsth = &exeQuery($mydbh, $myQuery);
    # while (my($departments)=$colsth->fetchrow_array()){
    # print "$departments \n";
    # }
    #}

      First: Please use <code></code> tags around your code.

      Second...and? What happens when you do that? What doesn't happen? What do you want to happen?


      ___________
      Eric Hodges
        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++; }
        }