(1) For example,
use strict;
use CGI qw/:standard/;
use Win32::ODBC;
$|++;
#
# s00h6q1.pl
#
# Return a table of all employees
sorted
# in ascending order of department.
Employees
# are listed under the supervisor.
#
# Use the DSN yue with the table
# s00h6(EmployeeId,
LastName, FirstName, EMail, SupervisorId,
#
Department) with EmployeeId being the primary key.
#
# DSN to be connected to.
Change this for porting.
my $DSN = "youraccount";
# Get the phones and emails.
# Open connection to the DSN.
my $db = new Win32::ODBC($DSN) || die "Can't
open ODBC $DSN" ;
my $sql= "select EmployeeId, LastName, FirstName,
EMail, SupervisorId, " .
"Department from s00h6 " .
"order by Department";
#
my $previousDepartment = "";
my $currentDepartment = "";
my %supervisors = ();
my %employeeInfo = ();
my $count = 0;
my $result = "";
$db->Sql($sql);
while($db->FetchRow()){
my %Data = ();
%Data = $db->DataHash();
$currentDepartment = $Data{'Department'};
if ($currentDepartment ne $previousDepartment)
{
# A
new department found, process the previous one.
if (keys %supervisors
> 0) {
# Process a department.
$result .= "<TR><TD>$previousDepartment</TD><TD>" .
deptString(\%supervisors, \%employeeInfo, 0) .
"</TD></TR>\n";
}
$previousDepartment
= $currentDepartment;
%supervisors
= ();
%employeeInfo
= ();
}
# Add current record
to the hashes.
$supervisors{$Data{'EmployeeId'}}
= $Data{'SupervisorId'};
$employeeInfo{$Data{'EmployeeId'}}
= '<A HREF="mailto:' .
$Data{'EMail'} . '">' . $Data{'FirstName'} . ' ' .
$Data{'LastName'} . '</A>';
}
if (keys %supervisors > 0) {
# Process
a department.
$result .= "<TR><TD>$previousDepartment</TD><TD>"
.
deptString(\%supervisors, \%employeeInfo, 0) .
"</TD></TR>\n";
}
$db->Close();
# Print the result.
print header,
start_html('Directory
Information'),
h1('Directory
Information'),
'<TABLE
BORDER="1" CELLPADDING="5" BGCOLOR="#FFCCCC">',
'<TR><TD>Department</TD><TD>Employees</TD></TR>',
$result,
'</TABLE>',
end_html;
exit 0;
#
# Prepare the HTML string for
all employees with
# the same supervisor.
#
sub deptString {
my %supervisors = %{$_[0]};
my %employee = %{$_[1]};
my $supervisor = $_[2];
my $result = "";
return "" if keys %supervisors
<= 0;
foreach (keys %supervisors)
{
if ($supervisors{$_}
eq $supervisor) {
$result .= "<LI>$employeeInfo{$_}</LI>";
$result .= deptString(\%supervisors, \%employeeInfo, $_);
}
}
$result = "<UL>$result</UL>"
if ($result);
$result;
}
(2) For example,
A {text-decoration:none;
font-family:Arial;
font-style:italic;
font-weight:200%;}
}
BODY {line-height:200%;}
TABLE {border-color: green;
border-style:
dotted;}
P:FIRST-LINE {color:blue;
font-size:200%;}
H1 {text-transform:uppercase;
font-size:250%;
background-image: url(stone1.gif);}
H1 STRONG {color: red}