#!/usr/bin/perl -w

use strict;
use Pg;

my $pizzaTk = Pg::connectdb("host=153.1.63.39 dbname=at73068");
    if ($pizzaTk->status != PGRES_CONNECTION_OK) {
        print "virhe";
}
my $pizzat = $pizzaTk->exec("select pnro as PizzaNumero,pnimi as PizzaNimi, phinta as PizzaHinta from pizza order by pnro");

my $lkm = $pizzat->nfields;
my @otsikot1;

for (my $i=0; $i<$lkm; $i++) {
    my $nimi = $pizzat->fname($i);
    push @otsikot1,$nimi;
}
print "Content-Type: text/html\n\n";
print <<XXX;
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fi" lang="fi">
  <head>
  <title>Pizzalista</title>
  </head>
  <body>

<h1>Menu</h1>

<table border="1" cellpadding="3" cellspacing="0">
XXX
    print "<tr>\n";
foreach my $ots (@otsikot1) {
    print "<th>$ots</th>\n";
}
print "</tr>\n";
while (my @rivi = $pizzat->fetchrow) {
    print "<tr>\n";
    foreach my $x (@rivi) {
	print "<td>$x</td>\n";
    }
    print "</tr>\n";
}

print <<XXX;
</table>
    <p><a href="http://validator.w3.org/check?uri=referer">
    <img style="border:0" src="http://www.w3.org/Icons/valid-xhtml10"
      alt="Liekk;;n tuo on valitia?"
      height="31" width="88"/>
      </a>
    </p>
  </body>
</html>
XXX










