in reply to Array of Arrays & Fetchrow

The simplest way to do what you want to do is using fetchrow_arrayref (assuming you're using DBI here and $ratings is a statement handle):
push @rows, $_ for $ratings->fetchrow_arrayref(); # @rows now contains references to rows. # You access rows and colums using: my $value=$rows[1]->[1]; # This would fetch the 2nd column of the 2nd row
FWIW, to get your code to work, drop some parentheses:
while ( @ratings = $ratings->fetchrow_array() ) { push @Array, [$rati ++ngs[0], $ratings[1]]; }

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: Array of Arrays & Fetchrow
by LTjake (Prior) on Nov 01, 2002 at 00:13 UTC
    Is there any reason why one couldn't use fetchall_arrayref?
    $rows = $ratings->fetchall_arrayref;


    --
    Rock is dead. Long live paper and scissors!
Re: Re: Array of Arrays & Fetchrow
by Willman023 (Scribe) on Nov 01, 2002 at 14:40 UTC
    Your right Robartes, your way is probably easier. Thanks for such a detailed explaination of your code, I only really used fetchrow_array until now, because I'm not too confortable with references.

    Where there's a Willman, there's a way!

      I may have spoke to soon. I used robartes code:

      push @rows, $_ for $ratings->fetchrow_arrayref(); print XML "$rows[0]->[0]:$rows[0]->[1]:$rows[1]->[0]:$rows[1]->[1]\n";
      And my output is 1111:1::

      So I added a: push @rows, $_ for $ratings->fetchrow_arrayref(); This is to get the second line from the DB.

      And my output is 2222:2:2222:2 instead of 1111:1:2222:2 like I thought it would be. Can anybody tell me what I'm doing wrong here?
      Thanks

      BW

        Hi, something's fishy indeed - probably my fault :). If you print the values of @rows after the push, what does it say (should say ARRAYREF(0x.....) )?

        CU
        Robartes-