Database Reference
In-Depth Information
my $ipnumber = $myarray[1];
my $datecreated = $myarray[2];
print”<TR><TD>$datecreated</TD><TD>$pagetitle</TD>
<TD>$ipnumber</TD></TR>”;
}
print “</TABLE>”;
The above also puts the column names in a header row. Notice that the row definition
and column names are outside of the loop, and the recurring rows are on the inside.
Here is the whole modified script with the error handling and reformatting included:
#!perl
BEGIN {
$| = 1;
open (STDERR, “>&STDOUT”);
}
use DBI;
print “Content-type: text/html\n\n”;
print “<html><TITLE>mytest2.pl</TITLE><body>\n”;
my $dbh =
DBI->connect('DBI:mysqlPP:mysqlfast:host=localhost',phpuser,abominable) or
die “\n\nConnect Error: “ . $dbh->errstr;
my $sth = $dbh->prepare('SELECT title, datecreated, ipnumber from webpage,
log
WHERE log.webpageid=webpage.id') or die “\n\nPrepare Error: “ . $dbh-
>errstr;
$sth->execute() || quit();
print “<TABLE border=1>”;
print “<TR><TD>Date Accessed</TD><TD>Page Title:</TD><TD>IP
Number</TD></TR>”;
while (@myarray = $sth->fetchrow_array()) {
my $pagetitle = $myarray[0];
my $ipnumber = $myarray[1];
my $datecreated = $myarray[2];
print”<TR><TD>$datecreated</TD><TD>$pagetitle</TD>
<TD>$ipnumber</TD></TR>”;
}
print “</TABLE>”;
print”<HR>Ok”;
print”</BODY></HTML>\n”;
If you run this you will see the results shown in Figure 15.10.
However, if you made a typing error while entering your script, you may have got differ-
ent results. Hopefully, the results will give you an indication of what the error was.
Search WWH ::




Custom Search