henry chen am Samstag, 25. Februar 2006 07.07:
> I can't seem to figure out how to alternate the bgcolor for each row that
> i'm printing from arrayref.  Is there a 'foreveryother' function that would
> allow me to put two lines in the loop?  Or is there someway I can put two
> rows of information and loop that?  Here's what I have so far.....
>
>
>
>
>
> my $rows = $dbhandle->selectall_arrayref($sql) || die $dbhandle->errstr;
>
>         if (@$rows) {
>           print "<center><table border=1 cellspacing=0 cellpadding=3
> width='70%'><tr>" .
> "<th>Title</th><th>Description</th><th>Price</th><th>Email</th></tr>";
>           foreach my $row (@$rows) {
>             print "<tr><td>" . join ("</td><td>", @$row) . "</td></tr>\n";
>           }
>           print "</table>\n</center>\n";
>         }
>         else {
>           print "<p><i>No matches found</i></p>\n";
>         }
>
> Thanks for the help!

Hi!

Beside the answer you got, you could consider using stylesheets to avoid 
hardcoding colors. So, you would not assign two different colors for the even 
and odd rows, but assign one of the two classes 'even' or 'odd', 

  ...<tr class='even'>...</tr>...<tr class='odd'>...</tr>...

and assign them colors via an external stylesheet. If you chose to change the 
colors later, you do it in one place: in the stylesheet.

This is alreay offtopic-not-perl-related, but to generalize this: 
It will make it *much* easier to maintain the (x)html if you
- always refer to an external stylesheet from every generated page
- assign css-classes to every x(html) element

The latter allows you to locate a specific element within the page by css at 
any later time: You are prepared to do layouting things you don't think of at 
the moment - only in one file.

Again, sorry for being offtopic.

Hans

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to