netroact
03-06-2006, 04:27 AM
I made a little module to display the table I use for several scripts. Because I use different MySql statements in each script, I just want to display the table. Here is part of the module:
package DisplayTable;
require Exporter;
our @ISA=qw(Exporter);
our @EXPORT=qw(display);
our $VERSION=1.00;
####################################################
sub display
{
print "Content-type:text/html\n\n";
print <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Portfolio Manager</title>
<style>
<!--
#table_title
{
text-align: center;
color: #000080;
font: 8pt arial;
}
#table
{
text-align: center;
color: #3366aa;
font: 8pt arial;
}
-->
</style>
</head>
<body>
<table border="1" bordercolor="#3366aa">
<tr bgcolor="f0f0f0">
<td height="30" align="center"><div id='table_title'><b>Date</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock Buy</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock Buy</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock EOD</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock EOD</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock Sell</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock Sell</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Spread</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Commission</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Confirm Fee</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Fees</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Interest</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Deposit</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Withdraw</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Securities Value</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Cash & Equiv</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Margin</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Net Equity</b></div></td>
</tr>
EOF
our @fields;
our $sth2;
#loop through the recordset returned by the query
while (@fields = $sth2->fetchrow())
{
print "<tr>";
print "<td align=center><table align=center><tr>";
print "<td align=center><div id='table'>$fields[1]/$fields[2]/$fields[3]</div></td></tr></table></td>";
I am getting this error:
Can't call method "fetchrow" on an undefined value at DisplayTable.pm line 71.
I'm assuming I need to know how to pass $sth2 to the module. What do I need to do?
Thanks FishMonger!
package DisplayTable;
require Exporter;
our @ISA=qw(Exporter);
our @EXPORT=qw(display);
our $VERSION=1.00;
####################################################
sub display
{
print "Content-type:text/html\n\n";
print <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Portfolio Manager</title>
<style>
<!--
#table_title
{
text-align: center;
color: #000080;
font: 8pt arial;
}
#table
{
text-align: center;
color: #3366aa;
font: 8pt arial;
}
-->
</style>
</head>
<body>
<table border="1" bordercolor="#3366aa">
<tr bgcolor="f0f0f0">
<td height="30" align="center"><div id='table_title'><b>Date</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock Buy</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock Buy</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock EOD</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock EOD</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock Sell</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Stock Sell</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Spread</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Commission</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Confirm Fee</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Fees</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Interest</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Deposit</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Withdraw</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Securities Value</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Cash & Equiv</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Margin</b></div></td>
<td height="30" align="center"><div id='table_title'><b>Net Equity</b></div></td>
</tr>
EOF
our @fields;
our $sth2;
#loop through the recordset returned by the query
while (@fields = $sth2->fetchrow())
{
print "<tr>";
print "<td align=center><table align=center><tr>";
print "<td align=center><div id='table'>$fields[1]/$fields[2]/$fields[3]</div></td></tr></table></td>";
I am getting this error:
Can't call method "fetchrow" on an undefined value at DisplayTable.pm line 71.
I'm assuming I need to know how to pass $sth2 to the module. What do I need to do?
Thanks FishMonger!