> 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?
>
fetchrow_hashref returns a row as a hash reference where the keys of the
hash are the columns of the table. Naturally your while loop loops over
each returned row temporarily storing the hash ref into $ref2... so, you
access your value with:
print $ref2->{'bib_database_id'};
Just as you would access any other hash reference. (Obviously the
'print' is just htere because I didn't know what you were doing with it).
> }
>
> Thanks,
> Tim
>
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>