Forum Moderators: coopster & phranque

Message Too Old, No Replies

Drawing tables to display database data in HTML

html in perl script

         

shaan1980

3:18 pm on Feb 26, 2004 (gmt 0)

10+ Year Member



Hi
I am a new bie to perl
I know we can use html in perl
but my issue is this
I am running a simple query on my tables
say slect * from meeting
and then i print out what I get this way

while(sth->fetch()){

print ("$mdate,$location,$agen,$min");
}
what i want to do is display this in a neat tabular way in HTML
so that the person seeing the site can see it in the form of a table
help please

tombola

9:52 pm on Feb 26, 2004 (gmt 0)

10+ Year Member



As you're a Perl newbie, I don't make it too complicated ;-)

print ("Content-type: text/html\n\n");
print "<html>\n";
print "<head>\n";
print "<title>your title</title>\n";
print "</head>\n";
print "<body>\n";
print "<table><n";
print "<tr>\n";
while(sth->fetch()){
print "<td>$mdate</td>\n";
print "<td>$location</td>\n";
print "<td>$agen</td>\n";
print "<td>$min</td>\n";
}
print "</tr>\n";
print "</table>\n";
print "</body>\n";
print "</html>\n";

shaan1980

2:12 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



hi that doesn't seem to work

I have pasted my code below
everyting seems simple enough not sure what the problem is
everything is working except the bit where i try to present it in tables

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

use CGI;
use File::Copy;
use CGI qw(:standard);
use DBI;

$query=new CGI;
$agendadir="/raid5/newhome/njicc/";
$month=param("Month");
$day=param("Day");
$year=param("Year");
$file1 = param('file');
$filedes=param('filedes');
$filetype=param('filetype');

print ("$filetype");
print ("$file1");
$file1 =~ s/.*[\/\\](.*)/$1/;
print ("$file1");
$newfilename1="$month"."$year"."$day"."$filedes";
$newfilename="$newfilename1.$filetype";
print("$newfilename");
$DATA= $query->upload("file");

my $success = open OUTPUTFILE,">$agendadir/$filedes/$newfilename";
unless($success){
print "Cannot open file!";
}
binmode OUTPUTFILE;

while (<$DATA>)
{
print OUTPUTFILE;
}

close OUTPUTFILE;

$dbname = '******';
$user = '*********';
$passwd = '*********';

$dbh = DBI->connect($dbname, $user, $passwd, 'Oracle');

if($dbh)
{
print ("Connection for the database successful");
}
else
{
die("Connection to the database unsuccessful");
}

my $sth=$dbh->prepare('SELECT * from meeting')or die "Couldn't prepare statement: " . $dbh->errstr;

if (!defined $sth ) {
die "Cannot prepare statement: $DBI::errstr\n";
}

$sth->execute()or die "Couldn't execute statement: " . $sth->errstr;

my ($mdate,$location,$agen,$agenext,$min,$minext);

$sth->bind_columns(\$mdate,\$location,\$agen,\$agenext,\$min,\$minext);

print ("i have executed my commands");
print ("Content-type: text/html\n\n");
print "<html>\n";
print "<head>\n";
print "<title>your title</title>\n";
print "</head>\n";
print "<body>\n";
print "<table><n";
print "<tr>\n";

while(sth->fetch())
{
print "<td>$mdate</td>\n";
print "<td>$location</td>\n";
print "<td>$agen</td>\n";
print"<td>$agenext<\td>\n";
print "<td>$min</td>\n";
print "<td>$minext</td>\n";
print "$mdate,$location,$agen,$agenext,$min,$minext";

}

print "</tr>\n";
print "</table>\n";
print "</body>\n";
print "</html>\n";

#print "$mdate,$location,$agen,$agenext,$min,$minext";

if ($sth->rows == 0) {
print "No names matched.\n\n";
}

$sth->finish;
$dbh->disconnect();

tombola

4:56 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



First, replace while(sth->fetch()) with while($sth->fetch())

If you want a nice HTML output, your first print statements (after the print Content-type on line#2) should be:
print "<html>\n";
print "<head>\n";
print "<title>your title</title>\n";
print "</head>\n";
print "<body>\n";

at the end:
print "</body>\n";
print "</html>\n";

Maybe it's a good idea to create a HTML file that displays all parameters you need (in table cells). When you're satisfied about the layout, you can integrate the HTML code in your script.

sorry, but I did not review the entire code, I've other plans today ;-)

shaan1980

7:24 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



thanks matter solved +

flashfan

9:58 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



Is there a way to page a real huge recordset?

Laxters

11:28 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



Yes - you can use the LIMIT and DATASEEK functions, and couple those with "page" parameters in the URL string.

For example, if you have a recordset of 150 rows, you can display 30 at a time and display Prev. and Next buttons to show the previous or next 30 records. Just Dataseek->30 or 60 or whatever and print those 30 records.