in reply to Re: Re: Can't retrieve all records
in thread Can't retrieve all records

Hi,

Someone else suggested that I use fetchrow_arrayref.

I modified my subroutine to incorporate this suggestion and I'm having problems with it.

Here's the code if someone can take a look and help me out.
sub get_customer { my ($dbh, $track_ref) = @_; $dbh = WebDB::connect (); my $sth = $dbh->prepare ("SELECT * FROM Shipments WHERE customer_id = +?"); $sth->execute($customer_id); while (my $track_ref = $sth->fetchrow_arrayref ()) print p $customer_id, print p $customer_item_number, print p $tracking_number, "\n"; }

Thanks.

Replies are listed 'Best First'.
Re: Re: Re: Re: Can't retrieve all records
by arthas (Hermit) on Jun 03, 2003 at 21:32 UTC

    fetchrow_arrayref() returns you an array reference, so you should use it in a way like this:

    while (my $track_ref = $sth->fetchrow_arrayref ()) { print $$track_ref[0]; # This prints the first field print $$track_ref[1]; # This prints the second field # ...and so on }
    If you plan to use this method, it's a good practice to avoid SELECT *, and specify in the query all the fields in the order you expect them to be. It works even with the first syntax, however you're going to need to adjust your code if for some reason you recreate your table with a different field order or with additional fields inserted in the middle.

    Michele.