Thread Verschachtelte Tabellen mit HTML::Template (13 answers)
Opened by Ronnie at 2003-10-22 11:39

Ronnie
 2003-10-22 14:49
#7432 #7432
User since
2003-08-14
2022 Artikel
BenutzerIn
[default_avatar]
Das ganze nochmal im fertigen Zustand:

Code: (dl )
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;
}


Wie kann ich im Hash direkt den Rückgabewert der Funktion &fetch_contact() referenzieren?

Code: (dl )
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
);


Gruss,
Ronnie

View full thread Verschachtelte Tabellen mit HTML::Template