Chas Owens am Samstag, 25. Februar 2006 07.17:
[...]
> Use the module operator (%) with an if statement to do different
> things in a loop:
>
> 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>"; my

> $i = 1;

my $i=0;

>     foreach my $row (@$rows) {
>         my $color;
>         if ($i % 2) { #odd rows

if (++$i % 2) { # odd rows

otherwise you'll get only odd rows :-)

>             $color = "#303030";
>         } else { #even rows
>             $color = "#000000";
>         }
>         print qq(<tr bgcolor="$color"><td>) . join ("</td><td>",
> @$row) . "</td></tr>\n";
>     }
>     print "</table>\n</center>\n";
> } else {
>     print "<p><i>No matches found</i></p>\n";
> }

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