Re: Multiple queries to populate drop down list boxes.

Mark Haney <MarkH-rOuQeLG7NUhWk0Htik3J/[email protected]> Thu, 4 Oct 2012 13:16:21 +0000
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
________________________________________
From: templates-bounces-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@public.gmane.org [templates-bounces-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@public.gmane.org] on behalf of Chad Wallace [[email protected]]
Sent: Thursday, September 27, 2012 3:02 PM
To: [email protected]
Subject: Re: [Templates] Multiple queries to populate drop down list boxes.

On Thu, 27 Sep 2012 17:10:39 +0000
Mark Haney <MarkH-rOuQeLG7NUhWk0Htik3J/[email protected]> wrote:

> >     my @rows_shift;
> >     while (my $row_shift = $sth->fetchrow_array() )
> >       {
> >       push @rows_shift, $row_shift;
> >       }

BTW, this is equivalent:

my $rows_shift = $sth->fetchall_arrayref();

So, in other words I don't really need the while loop? That was used in the previous instance because of the fact that data is an array and not just a list. (In fact I have another page where the elements are identified in the script.  I don't remember why I didn't do this one like that.  

And then instead of \@rows_shift, you pass $rows_shift to your $vars.

Similarly for the factories one, you could use this:

my $rows_factory = $sth->fetchall_arrayref({});

But you would also need to add aliases to your column names, so they
are named "id" and "abbr", or change the template to use their actual
column names.

TIMTOWTDI, of course!


> #The part where it gets passed to the HTML:
>
> >     my $file = 'templates/shift_rpt.html';
> >     my $vars = {
> >     'cgi' =>CGI->new(),

You probably don't want to make a new CGI object here.  Try passing in
the one that's already made ($cgi).  I'm not entirely sure, but I think
when CGI does its parsing, it's destructive about it, so a second
object wouldn't necessarily get the same data.

So far, I've not had a problem with creating a new CGI object there.  And I really can't see why it would suddenly be a problem now, but only for one variable.  For now, I think if it ain't broke, I won't try to fix it.  One thing at a time.


--

C. Chad Wallace, B.Sc.
The Lodging Company
http://www.lodgingcompany.com/
OpenPGP Public Key ID: 0x262208A0


_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates