For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > April 2005 > print table inside while









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author print table inside while
Nikos

2005-04-27, 8:57 am

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
s of using it.
Maybe the error is that the print table is display many times inside the
loop?

Please help.
Mahesh Asolkar

2005-04-27, 8:57 am

Nikos wrote:

> 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
> s 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 s 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.
--
Mahesh Asolkar
asolkar-at-gmail-dot-com
Nikos

2005-04-27, 8:57 am

Mahesh Asolkar wrote:
> Nikos wrote:
>
>
> I am not entirely sure what you s 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.


Yes iam sign 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.
Mahesh Asolkar

2005-04-27, 3:58 pm

Nikos wrote:
> Mahesh Asolkar wrote:


>
> Yes iam sign 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.
--
Mahesh Asolkar
asolkar-at-gmail-dot-com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com