MySQL Forums
Forum List  »  Perl

Displying field names and data
Posted by: Rob Warren
Date: December 06, 2006 03:37PM

I'm a Uni student and new to Perl and MySQL.

I have the following code to select data from a display it in a HTML table but it does not give me the field names at the top of the table. Can anybody please help.

#!/usr/bin/perl -w
print "Content-type: text/html\n\n";

print "<table border=2 border color=white table width = 100% table bgcolor=#CCCC66>\n";

use DBI;
$dbh = DBI->connect('dbi:mysql:db_name','db_user','db_password')
or die "Connection Error: $DBI::errstr\n";
$sql = "SELECT * FROM Table_name";
$sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
#or die "SQL Error: There was an error with your query please try again\n";
while (@row = $sth->fetchrow_array) {

print "<tr>\n";
foreach $td (@row) {print "<td align=center>$td</td>\n";}
print "</tr>\n";

}
print "</table>";

print "<html>";

Options: ReplyQuote


Subject
Written By
Posted
Displying field names and data
December 06, 2006 03:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.