9 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
sub subSelect() {my $data = $dict->{DB}->get("SELECT pos,id,awk FROM awk");
foreach( @{$data} ) {my $line ={id=>$_->{id}, awk=>$_->{awk}};
$line->{ifSelected } = 1 if (defined($dict->{id}) and $_->{id} == $dict->{id});
push(@{$dict->{loopSelect}}, $line);
}
if (defined($dict->{id}) and $dict->{id} ne "") {
my $data = $dict->{DB}->get("SELECT awk FROM awk WHERE id=$dict->{id}");
while (my ($k, $v) = each(%{@{$data}[0]})) { $dict->{$k} = $v; }
}
return(1);
}
1
2
3
4
5
<select name="id" onchange="go('select');" width="90" style="width:90;">
<option value=""></option>
<tmpl_loop loopSelect>
<option value="<tmpl_var id>" <tmpl_if ifSelected>selected="selected"</tmpl_if>><tmpl_var awk></option></tmpl_loop>
</select>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
my @array = ();
foreach my $i (0..$#$arrayRef) { # iteriere ueber den Index der Listenreferenz
push (@array, $arrayRef->[$i]);
# jetzt eine Hashreferen der neuen Zeile erzeugen:
my $hashRef = {
id => $i+1,
ifselected => 0,
awk => "2 Text ". (($i+1)*2) . " fuer das " . ($i+1) . ". Dropdownfeld",
};
push (@array, $hashRef); # und auch zu @array hinzufuegen
} # foreach
# @array als templateparameter uebergeben
$template->param(loopSelect => \@array);
1
2
3
4
5
6
7
<TMPL_LOOP NAME=SELECTS>
<TMPL_LOOP NAME=SUBSELECTS>
<select name="bla">
<option value="<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=AWK></select>
</select>
</TMPL_LOOP>
</TMPL_LOOP>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$data = [
{ # select 1
subselects => [ # daten1
{ id => 1, awk => 'irgendwas' },
{ id => 2, awk => 'irgendwas' },
{ id => 3, awk => 'irgendwas' },
],
},
{ # select 2
subselects => [ # daten2
{ id => 1, awk => 'irgendwas' },
{ id => 2, awk => 'irgendwas' },
{ id => 3, awk => 'irgendwas' },
],
},
];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /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();
9 Einträge, 1 Seite |