Leser: 2
|< 1 2 >| | 16 Einträge, 2 Seiten |
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
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use HTML::Template::Compiled;
my $tmpl = 'Database.tmpl';
my $template = HTML::Template::Compiled(filename => $tmpl);
my ($user,$pass,$db,$host) = ("user","passwort","datenbank","host");
my $dbh = DBI->connect("DBI:mysql:$db:$host",$user,$pass) or die $DBI::errstr;
my $stmt = q~SELECT * FROM tabelle~;
my $sth = $dbh->prepare($stmt) or die $dbh->errstr();
$sth->execute() or die $dbh->errstr();
my @values;
while(my ($col1,$col2) = $sth->fetchrow_array()){
my $class = 0;
$class = 1 if $col2 eq 'hallo';
push @values, {VALUE => $col1, CLASS => $class};
}
$sth->finish();
$dbh->disconnect();
$template->param(SCHLEIFE => \@values);
print $template->output();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<html>
<head>
<title>Test</title>
<style type="text/css">
.red{ color: red; }
.green{ color: green; }
</style>
</head>
<body>
<table>
<!-- TMPL_LOOP NAME=SCHLEIFE -->
<tr>
<td><img src="/pfad/zu/warndreieck.jpg"></td>
<td><span
class="<!-- TMPL_IF NAME=CLASS -->red<!-- TMPL_ELSE -->green<!-- /TMPL_IF -->">
<!-- TMPL_VAR NAME=VALUE --></span>
</td>
</tr>
<!-- /TMPL_LOOP -->
</table>
</body>
</html>
|< 1 2 >| | 16 Einträge, 2 Seiten |