Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How to read multiple tables into arrays

by dragonchild (Archbishop)
on Nov 10, 2008 at 22:58 UTC ( #722737=note: print w/ replies, xml ) Need Help??


in reply to How to read multiple tables into arrays

Take a look at an ORM, such as DBIx::Class.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?


Comment on Re: How to read multiple tables into arrays
Re^2: How to read multiple tables into arrays
by pinkgladiator (Initiate) on Nov 11, 2008 at 01:56 UTC
    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++;
    }
    }
      • 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).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://722737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-12-25 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls