Multiple queries to populate drop down list boxes.
Mark Haney <MarkH-rOuQeLG7NUhWk0Htik3J/[email protected]> Thu, 27 Sep 2012 17:10:39 +0000
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <[email protected]> |
I've been fighting this problem off and on for a couple of months now. It's not something I've spent every moment on, just when I had the time. Now, though, it's necessary I get this working.
What I'm trying to do is to populate 2 drop down lists from the perl code to the html template. I've got one working perfectly, and it's no problem for just one, but the second one is a real PITA. The second one is a separate SQL query (and the query works, btw) using the same handle, etc. My code is below:
> my $cgi = new CGI;
> my $dbh = DBI->connect(config('data_source'), config('username'), config('password'));
> my $dao = EmbMon::DAO->new($dbh);
> my $sql = qq/SELECT factory_id, abbreviation from factory/;
> my $sth = $dbh->prepare($sql);
> $sth->execute();
>
>
> my @rows_factory;
> while ( my @factory_data = $sth->fetchrow_array() )
> {
> push @rows_factory, {'id' => $factory_data[0], 'abbr' => $factory_data[1]};
> }
> $sth->finish();
> # End of Factory codes routine
>
> # Get Shift data (names,days of week, times) for use in the pulling of report data for the shifts
>
> $sql = qq/SELECT shift_name from shifts group by shift_name/;
> $sth = $dbh->prepare($sql);
> $sth->execute();
>
>
>
> my @rows_shift;
> while (my $row_shift = $sth->fetchrow_array() )
> {
> push @rows_shift, $row_shift;
> }
> $sth->finish();
>
> # End Get shift data routine
#The part where it gets passed to the HTML:
> my $file = 'templates/shift_rpt.html';
> my $vars = {
> 'cgi' =>CGI->new(),
> 'factories' => \@rows_factory, # This moves the data from the array into a var that gets carried into the template
> 'shifts' => \@rows_shift # This moves the custom shifts names into the dropdown box for the reports
> };
>
I've tried everything I can think of, but all it's doing is passing the name of the perl script (shift_rpt.pl) to the dropdown box. The factory one works as advertised. I just don't have a clue why one works and the other doesn't.
Any ideas? Or perhaps a better way to do this?
--
Mark Haney
Software Developer/Consultant
AB Emblem
markh-rOuQeLG7NUhWk0Htik3J/[email protected]
Linux marius.homelinux.org 3.5.1-1.fc17.x86_64 GNU/Linux
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates