!/usr/bin/perl -w #load Modules use strict; use DBI (); use HTML::Template; #open the xhtml template my $template = HTML::Template->new(filename => '../Documents/qms.version0.03/html.files/navigation.xhtml'); ################# ##Database part## ################# #Database Variable my $dataSource = "dbi:mysql:qms"; my $user = "root"; my $passwd = "psalm5015"; #Database Connect my $dbh = DBI->connect($dataSource, $user, $passwd, { "RaiseError" => 0, "AutoCommit" => 1, } ); unless ($dbh) { print("Fehler beim Verbindungsaufbau zur Datenbank (Code = $DBI::err)\n" ); exit(1); } #Vorbereiten der SELECT-STATEMENTS my $sql = "SELECT * FROM navi"; my $sth = $dbh->prepare($sql); unless($sth) { print("Konnte SQL-STATEMENTS nicht vorbereiten!\n"); } #execute the SELECT-STATEMENTS unless($sth->execute()) { print("Fehler beim Ausfüren von'$sql'-STATEMENT\n", "Fehler = ' $sth->errstr() '\n" ); exit(1); } #attributes my $db_content; my @navi_content = (); my @navi_content4show = (); #fill @array with database content while(my @db_content = $sth->fetchrow_array()) { foreach $db_content(@db_content) { #set element on array for xhtml-link and xhtml show push(@navi_content,$db_content); push(@navi_content4show,ucfirst($db_content)); } } ################# ##Template part## ################# #initialize an array to hold yout loop my @loop_data = (); while(@navi_content and @navi_content4show) { #get a fresh hash for the row data my %row_data; #fill in this row $row_data{NAVI_CONTENT} = shift(@navi_content); $row_data{NAVI_CONTENT_FOR_SHOW} = shift(@navi_content4show); #the crucial step - push a reference to this row into the loop! push(@loop_data, \%row_data); } #finally, assign the loop data to the loop param, again with a refernce. $template->param(NAVI_LOOP => \@loop_data); #print Header print("Content-Type: text/plain\n\n"); print $template->output(); exit(0); END { if ($dbh) { $dbh->disconnect(); } }