This is probably a very newbie-type of question, but I have this code 
which a question noted by the ****** below.

my $sth = $dbh->prepare("SELECT * FROM patrons WHERE patron_id=$patron_id");
    $sth -> execute();

    # check to see if record is in database
    if (my $ref = $sth->fetchrow_hashref()) {
       # update record
       print "Updating $name_f $name_l\n";
       $dbh->do("UPDATE patrons SET name_f=$name_f, name_l=$name_l, 
email=$email, discipline_id=$disc_id, rank_id=$status, username=$un");
    }
    else {
       # insert new record
       print "Inserting $name_f $name_l\n";
       $dbh->do("INSERT INTO patrons (patron_id, name_f, name_l, email, 
discipline_id, username, password, can_contact, rank_id, template_id) 
VALUES ($patron_id, $name_f, $name_l, $email, $discipline_id, $un, $pwd, 
'1', $status, $template_id);

       # join patrons to respective disciple default lists
       # bib_databases
       my $sth2 = $dbh->prepare("SELECT bib_database_id FROM 
items4DisBibdatabases WHERE discipline_id=$disc_id");
       $sth2 -> execute();
       while (my $ref2 = $sth2->fetchrow_hashref()) {

******   NEED TO use each bib_database_id ******
how do I reference it?  with $_ or something else?

There are several ways of referencing... I don't use the method
fetchrow_hashref so I can't answer that... but you may wish to look at
bind_column method or in this case you could:

<snip>
while (my $ref = $sth2-fetch) {
        my $this_bib_database_id = $ref->[0]; # or just use $ref->[0]
...
}
</snip>

FYI ... 

I would just do the update with the do method then see if anything was
updated... if nothing updated then do the insert... then you would not need
to do the prepare, execute, and the select... "assuming" that the ONLY thing
you are trying to do with those statements

Hope this helps

jwm

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to