Tim McGeary wrote:
> This is probably a very newbie-type of question, but I have this code
> which a question noted by the ****** below.
>
[snip]
> # join patrons to respective disciple default lists
> # bib_databases
> my $sth2 = $dbh->prepare("SELECT bib_database_id FROM
> items4DisBibdatabases WHERE discipline_id=$disc_id");
Use placeholders rather than interpolating values.
> $sth2 -> execute();
> while (my $ref2 = $sth2->fetchrow_hashref()) {
>
> ****** NEED TO use each bib_database_id ******
> how do I reference it? with $_ or something else?
You would reference the value through $ref2->{bib_database_id} (but see the
DBI documentation under "FetchHashKeyName")
But why use fetchrow_hashref here? You've explictly named the column, so why
not just:
while (my ($bib_database_id) = $sth2->fetchrow_array) {
...
Is there only one row per discipline_id? If so, you can collapse the whole
prepare/execute/fetch/finish process into:
my ($bib_database_id) = $dbh->selectrow_array("select ... ");
Or if there are multiple rows returned, you can grab them all in one step:
my $aref = $dbh->selectcol_array("select ... ");
for my $bib_database_id (@$aref) {
....
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>