Re: multiple fields from SQL query --Update

Mark Haney <markh-rOuQeLG7NUhWk0Htik3J/[email protected]> Thu, 24 May 2012 14:14:48 -0400
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
On 05/24/2012 10:52 AM, Mark Haney wrote:
> I've got a query in my perl code to pull 2 fields from a database
> (abbreviation, factory_id), one of which is used to populate a dropdown
> box (abbreviation). However, I will need to pass /both/ fields to the
> CGI script that I'm calling from the form that has the dropdown box. How
> do I do that? Here's what I have so far:
>
> shift_rpt.pl:
>
> my $sql = qq/SELECT factory_id, abbreviation from factory/;
> my $sth = $dbh->prepare($sql);
> $sth->execute();
>
>
> my $row_factory;
> my @rows_factory;
> while ($row_factory = $sth->fetchrow_array)
> {
> push @rows_factory, $row_factory; # This moves each row into the array
> @rows
> }
> $sth->finish();
>

I've had a couple of good suggestions on how to handle this, but I'm 
obviously missing something.  In the WHILE loop above, I'm not getting 
both fields from the query.  I.e. I'm getting the last element of the 
query (abbrev) pushed into the array @rows_factory but not the 
factory_id.  I'm guessing it's due to the fact that I'm fetching the row 
into a scalar ($row_factory) and not an array.  Correct?

I just can't seem to get the logic of this straight in my head.  Maybe 
I'm over-complicating things because of the toolkit.  Seems to me like 
the toolkit is sitting there complicating my thought process when it 
really shouldn't.



-- 

Mark Haney
Software Developer/Consultant
AB Emblem
markh-rOuQeLG7NUhWk0Htik3J/[email protected]
Linux marius.homelinux 3.3.6-3.fc16.x86_64 GNU/Linux