Leser: 1
|< 1 2 >| | 14 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
<table>
<tr>
<td>
<table id="Mitarbeiter"> (...) </table>
</td>
</tr>
<tr>
<td>
<table id="Detailinformation"> (...) </table>
</td>
</tr>
<table>
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
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
my ($dbh, $sth);
$dbh = DBI->connect ("DBI:mysql:host=192.168.0.1;database=myDB",
"user", "pw", {PrintError => 0, RaiseError => 1});
&fetch_ent();
$dbh->disconnect();
exit(0);
sub fetch_ent {
my $sth = $dbh->prepare (" SELECT Firma, Strasse, PLZ, Ort, EID
FROM firma
WHERE Firma LIKE 'N%'
");
$sth->execute();
while (my ($firma, $strasse, $plz, $ort, $eid) = $sth->fetchrow_array()) {
print "<tr bgcolor='#EEEEEE'><td>\n",
"<table class='blind'><tr>",
"<td>$firma</td><td>$strasse</td><td>$plz</td><td>$ort</td>",
"</tr></table>",
"</td></tr>\n",
"<tr bgcolor='#FFFFDD'><td>\n";
&fetch_contact($eid);
print "</td></tr>\n";
}
$sth->finish();
}
sub fetch_contact {
my $eid = shift @_;
my $sth = $dbh->prepare (" SELECT Name, Vorname
FROM person
WHERE EID = '$eid'
");
$sth->execute();
while (my ($nachname, $vorname) = $sth->fetchrow_array()) {
print "<table class='blind'><tr>",
"<td>$nachname</td><td>$vorname</td>",
"</tr></table>";
}
$sth->finish();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
while (my ($nachname, $vorname) = $sth->fetchrow_array()) {
my %row = (
nachname => $nachname,
vorname => $vorname,
);
push(@loop, \%row);
}
$sth->finish();
my $template = HTML::Template->new(filename => 'staff2.tmpl');
$template->param(staff_loop => \@loop);
#print "Content-Type: text/html\n\n";
print $template->output;
1
2
3
4
5
my %row = (
nachname => $nachname,
vorname => $vorname,
id => $ref_auf_innere_struktur
);
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
<TMPL_LOOP NAME="firma_loop">
<TABLE BORDER=1>
<TR>
<TD>
<TABLE>
<TR>
<TD><TMPL_VAR NAME="Firma"></TD>
<TD><TMPL_VAR NAME="Strasse"></TD>
<TD><TMPL_VAR NAME="PLZ"></TD>
<TD><TMPL_VAR NAME="Ort"></TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD>
<TMPL_LOOP NAME="staff_loop">
<TABLE>
<TR>
<TD><TMPL_VAR NAME="Nachname"></TD>
<TD><TMPL_VAR NAME="Vorname"></TD>
<TD><TMPL_VAR NAME="Telefon"></TD>
<TD><TMPL_VAR NAME="Fax"></TD>
<TD><TMPL_VAR NAME="Email"></TD>
</TR>
</TABLE>
</TMPL_LOOP>
</TD>
</TR>
</TABLE>
</TMPL_LOOP>
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
#!/usr/bin/perl -w
use strict;
use HTML::Template;
# open the html template
my $tt = <<USAGE
Start
<TMPL_LOOP AUSSEN>
Loop Nummer <TMPL_VAR NUMMER>:
<TMPL_LOOP INNEN>
innerer Loop <TMPL_VAR LETTER>
</TMPL_LOOP>
</TMPL_LOOP>
Ende
USAGE
;
my $template = HTML::Template->new(scalarref => \$tt,
# option => 'value',
# die_on_bad_params => 0,
);
$template->param(AUSSEN => [ { NUMMER => 1,
INNEN => [
{ LETTER => 'a1' },
{ LETTER => 'b1' },
]
},
{ NUMMER => 2,
INNEN => [
{ LETTER => 'a2' },
{ LETTER => 'b2' },
]
},
]
);
print $template->output;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Start
Loop Nummer 1:
innerer Loop a1
innerer Loop b1
Loop Nummer 2:
innerer Loop a2
innerer Loop b2
Ende
Quote<TMPL_LOOP>s within <TMPL_LOOP>s are fine and work as you would expect. If the syntax for the param() call has you stumped, here's an example of a param call with one nested loop:
Code: (dl )1
2
3
4
5
6
7
8
9$template->param(LOOP => [
{ name => 'Bobby',
nicknames => [
{ name => 'the big bad wolf' },
{ name => 'He-Man' },
],
},
],
);
Basically, each <TMPL_LOOP> gets an array reference. Inside the array are any number of hash references. These hashes contain the name=>value pairs for a single pass over the loop template.
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
63
64
65
66
67
68
69
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
use HTML::Template;
my ($dbh, $sth);
my @firma_loop;
my @contact_loop;
$dbh = DBI->connect ("DBI:mysql:host=192.168.0.1;database=myDB",
"user", "pw", {PrintError => 0, RaiseError => 1});
&fetch_ent();
$dbh->disconnect();
exit(0);
sub fetch_ent {
my $sth = $dbh->prepare (" SELECT Firma, Strasse, PLZ, Ort, EID
FROM firma
WHERE Firma LIKE 'N%'
");
$sth->execute();
while (my ($firma, $strasse, $plz, $ort, $eid) = $sth->fetchrow_array()) {
my @inner_loop = &fetch_contact($eid);
my %row = (
firma => $firma,
strasse => $strasse,
plz => $plz,
ort => $ort,
contact_loop => \@inner_loop
);
push(@firma_loop, \%row);
}
$sth->finish();
my $template = HTML::Template->new(filename => 'customer2.tmpl');
$template->param(firma_loop => \@firma_loop);
#print "Content-Type: text/html\n\n";
print $template->output;
}
sub fetch_contact {
my $eid = shift @_;
my @contact_loop;
my $sth = $dbh->prepare (" SELECT Name, Vorname, Telefon, Fax, Email
FROM person
WHERE EID = '$eid'
");
$sth->execute();
while (my ($nachname, $vorname, $telefon, $fax, $email) = $sth->fetchrow_array()) {
my %row = (
nachname => $nachname,
vorname => $vorname,
telefon => $telefon,
fax => $fax,
email => $email
);
push(@contact_loop, \%row);
}
$sth->finish();
return @contact_loop;
}
1
2
3
4
5
6
7
8
my @inner_loop = &fetch_contact($eid);
my %row = (
firma => $firma,
strasse => $strasse,
plz => $plz,
ort => $ort,
contact_loop => \@inner_loop
);
|< 1 2 >| | 14 Einträge, 2 Seiten |