in reply to DBI - retrieving a specific row

You can fetch all the records as a 2D array ref and then directly access record 4. Each field of record 4 can then be accessed using the elements of the 2nd array.
#get array ref my $results=$sth->fetchall_arrayref; #rec 4 is array element 3 due to the 0 element #my $field=$result->[row][fieldno] my $field1=$results->[3][0]; my $field2=$results->[3][1]; my $field3=$results->[3][2];
Alternatively you fetch an array or array ref row by row with
my @results=$sth->fetchrow_array; my $arrayref=$sth->fetchrow_arrayref;
You can't retrieve record 4 only without a loop unless your sql statement returns only one record. You can usually specify the rows to return with a LIMIT clause

Replies are listed 'Best First'.
Re: Re: DBI - retrieving a specific row
by beebware (Pilgrim) on Feb 04, 2002 at 13:07 UTC
    If it's a large database you are handling (ie lots of columns), that's (the 2D array method) is not going to be the most memory friendly method - but the loop and LIMIT is worth considering.