print table inside while

N

Nikos

ok the first part that loads the values is done, here it is :)

#===============================================================================

my @row;
my $sth = $dbh->prepare( "INSERT INTO games( gamename, gamedesc,
gamecount) VALUES (?, ?, ?)" );

open (FILE, "<../data/games/perigrafes.txt") or die $!;
while (<FILE>) {
chomp;

@row = split /\t/;
push @row, 0;

$sth->execute( @row );
}
close FILE;

#===============================================================================



And the print out in games.pl is ok except that it does nto display the
table specification formatting:

Code:

my $row;
my $sth;
$sth = $dbh->prepare( "SELECT * FROM games" );
$sth->execute();

while ( $row = $sth->fetchrow_hashref ) {

print table( {class=>'games'},
Tr(
td( submit( -name=>'game', -value=>$row->{gamename} )),
td( $row->{gamedesc} ),
td( $row->{gamecount} )
)
)
}



How should i write it so for the snipper touse the classes and print out
the table and colort correctly. ths style.css file is ok but it is not
seek of using it.
Maybe the error is that the print table is display many times inside the
loop?

Please help.
 
M

Mahesh Asolkar

Nikos said:
while ( $row = $sth->fetchrow_hashref ) {

print table( {class=>'games'},
Tr(
td( submit( -name=>'game', -value=>$row->{gamename} )),
td( $row->{gamedesc} ),
td( $row->{gamecount} )
)
)
}

How should i write it so for the snipper touse the classes and print out
the table and colort correctly. ths style.css file is ok but it is not
seek of using it.
Maybe the error is that the print table is display many times inside the
loop?

I am not entirely sure what you seek here. But I would write the above
loop using start_table and end_table, on the lines of:

--- sorry, untested code ---
print start_table ({class=>'games'});
while ( $row = $sth->fetchrow_hashref ) {
print Tr(
td( submit( -name=>'game', -value=>$row->{gamename} )),
td( $row->{gamedesc} ),
td( $row->{gamecount} )
)
}
print end_table;
------

This way there will be one table with a bunch of rows, as against a
bunch of tables with one row each.

More details at (section from CGI.pm documentation):
http://tinyurl.com/d7aa8

HTH,
Mahesh.
 
N

Nikos

Mahesh said:
I am not entirely sure what you seek here. But I would write the above
loop using start_table and end_table, on the lines of:

--- sorry, untested code ---
print start_table ({class=>'games'});
while ( $row = $sth->fetchrow_hashref ) {
print Tr(
td( submit( -name=>'game', -value=>$row->{gamename} )),
td( $row->{gamedesc} ),
td( $row->{gamecount} )
)
}
print end_table;

Yes iam seekign that exatcly you describes but for some reason the table
formatting does not being applied although the path to the style.css
file is correct and the formatiing directives in the file is this:

#info games {
background-image : url(/data/images/blue.jpg);
width: 80%;
color: lime;
text-align: center;
font: 18px comic;
border: 8px ridge magenta;
border-collapse: : collapse;
}

I dont see neither alignment, neither colors, neither table borders,
neither backgrounds nothing at all.

I run your code but what i see is the rows one after another even
without a '\n' after each row.
 
M

Mahesh Asolkar

Nikos said:
Mahesh Asolkar wrote:
Yes iam seekign that exatcly you describes but for some reason the table
formatting does not being applied although the path to the style.css
file is correct and the formatiing directives in the file is this:

There could be so many factors affecting this. Someone in the CSS
related group should help you better. But in any case...
#info games {

I think this needs to be,

#info .games {
background-image : url(/data/images/blue.jpg);
width: 80%;
color: lime;
text-align: center;
font: 18px comic;
border: 8px ridge magenta;
border-collapse: : collapse;
}

I dont see neither alignment, neither colors, neither table borders,
neither backgrounds nothing at all.

I'd make sure that the table is contained in a 'div' with id="info".
I run your code but what i see is the rows one after another even
without a '\n' after each row.

If you mean the page source is not pretty, try using CGI::pretty instead.

Mahesh.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top