hi,
I am new to tt2. I am trying to display the particulars of our employees'
salary on a browser by accessing the database through tt2.

The problem I am facing is that the database table is horizontal in
structure rather than being vertical.
The table has separate  columns for each item of salary (like basic_salary,
dearness_allowance, house_rent_allowance,
professional_qualification_allowance, and fixed_personal_allowance) in
addition to the employee_number column, instead of just having the following
3 columns - employee_number, item_description, amount.

If I turn the data around into a temporary vertical table, I am able to
display the item_description and the amount on the browser by suitably
adapting the examples 9-1 and 9-2 in chapter 9 of the Perl Template Toolkit
book and using the WRAPPER and BLOCK directives from chapter 2. With the
horizontal table, however, I am unable to display the column name and the
column value. Perl DBI has a fetchrow_hashref method for fetching the names
and values of columns into a hash. I experimented with that, but couldn't
make any progress because I didn't know the exact syntax for it in tt2.

I am giving the corresponding perl code. Can someone show how it can be
integrated into tt2?

#! /usr/bin/perl

use warnings;
use strict;

my($dbh,$sth,$hash_ref,$key);

use DBI;
$dbh = DBI->connect('dbi:mysql:tt2','user_name','user_password');
$sth = $dbh->prepare('SELECT * FROM salary_data');
$sth->execute();
while ($hash_ref = $sth->fetchrow_hashref) {
foreach $key(keys %$hash_ref) {
print "$key = $hash_ref->{$key}\n";
    }
     }

jagdish eashwar
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to