Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Fetchrow_array() confusion?

Quote Reply
Fetchrow_array() confusion?
my $test = $self->table('apps')->select({'UserID' => $user}, ['color', 'amount'])->fetchrow_array();

This supposed to bring back values for color and amount, but only brings back value of the "amount".
How do I get the value of the "color" to come up also?
Quote Reply
Re: [Suomi] Fetchrow_array() confusion? In reply to
You are using fetchrow_array but applying the returned value to a scalar (my $test)

You need my @test
Quote Reply
Re: [PaulW] Fetchrow_array() confusion? In reply to
This is from the help files...
Quote:
my $sth = $obj->select ( { Col => Val }, ['Col2', 'Col3'] );

is equivalant to ``SELECT Col2,Col3 FROM Table WHERE Col => 'Val'''.

And I dont see "@" sign... also I dont see fetchrow either...

I dont quite understand the perl that well...
Any help is welcome, how to get this thing done...
ie get or select 2 fields form the record and print them on the screen?
Quote Reply
Re: [Suomi] Fetchrow_array() confusion? In reply to
That example isn't using fetchrow_array to select from the database.

array is the keyword (although in the case of fetchrow_hashref you'd use $var not %var as it is a hash reference).

Anyway fetchrow_array returns the data as an array and so you need to use my @array


Quote Reply
Re: [Suomi] Fetchrow_array() confusion? In reply to
Hi,

Try:

my ($color, $amount) = $self->table('apps')->select({'UserID' => $user}, ['color', 'amount'])->fetchrow_array();

As paul mentioned, fetchrow array is returning an array of values, since you were assigning it to a single variable, you only got the first result. Everything else looks good.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Fetchrow_array() confusion? In reply to
Thanks Alex.