#! /usr/bin/perl use warnings; use strict; use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my $dsn = "...."" my ($user, $password) = ('user', 'password'); my $cgi = CGI->new(); my $dbh = DBI->connect("dbi::ODBC:$dsn", $user, password); unless ($dbh) { die "Error in connect: ", $DBI->errstr, "\n"; } # unless my $statement = qq~SELECT dropdown, id, akw, isselected FROM tabellenname ORDER BY dropdown, id~; my $sth = $dbh->prepare($statement); unless ($sth) { die "Error in preparing SQL: ", $dbh->errstr, "\n"; } # unless $sth->execute() or die "Error in executing SQL: ", $dbh->errstr, "\n"; my @selects = (); my $lastDropdown = '': while (my $line = $sth->fetchrow_hashref()) { my $dropdown = $line->{dropdown}; delete($line->{dropdown}; # in die unterliste hinzufuegen, wenn diese dropdown schon # mal vorkam if ($dropdown eq $lastDropDown) { push (@{ $selects[-1]->{subselect} }, $line); } # if # sonst naechstes select (fuege neues element der hauptliste hinzu else { push (@selects, { subselect => [ $line ], dropdown => $dropdown } ); } # else } # while $sth->finish(); # neues template erzeugen my $template = HTML::Template->new( filename => '.....', # cached die templates => schneller, aber nicht notwendig shared_cache => 1, ) or die "Error: couldn't read new Template: $!\n"; # template fuellen $template->param(SELECT => $selects); # eventuell weitere parameter ... # html-header ausgeben print $cgi->header(-type => 'text/html'); print $template->output();