Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks!
I have this part of my code here to demonstrated what I am trying to do, which is alternating the colors of the rows based on the query results. I know there are many ways of doing this using odd and even numbers, but because of the nature of this particular query results the values of the counter "$i" will not be in order or sequence, this block of code will print the values of $i as:
0 2 14 15 16 19 20
I am thinking that the only way is to compare the values of $i and if they are different assign a value I could use to do the color alternation, but I am running out of ideas, any help would be very appreciated, thanks for the help!
I have this part of my code here to demonstrated what I am trying to do, which is alternating the colors of the rows based on the query results. I know there are many ways of doing this using odd and even numbers, but because of the nature of this particular query results the values of the counter "$i" will not be in order or sequence, this block of code will print the values of $i as:
0 2 14 15 16 19 20
I am thinking that the only way is to compare the values of $i and if they are different assign a value I could use to do the color alternation, but I am running out of ideas, any help would be very appreciated, thanks for the help!
for (my $i = 0; $i < @$sql; $i++) { my $user = $sql->[$i]{user}; if($unique{$user}) { next; } $unique{$user} = 1; my $show = "<a href=\"show.pl?name=$name\">$name</a>"; my $first = $sql->[$i]{first}; my $last = $sql->[$i]{last}; my $tel = $sql->[$i]{tel}; my $email = $sql->[$i]{email}; + if ($i % 2) { $data = "$data<tr><td>$last, $first</td> <td>$show</td> <td>$email</td> </tr>"; }else { $data = "$data<tr><td>$last, $first</td> <td>$show_link</td> <td>$email</td> </tr>"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Alternating Table Row Colors Help!
by samarzone (Pilgrim) on May 05, 2010 at 18:14 UTC | |
Re: Alternating Table Row Colors Help!
by Herkum (Parson) on May 05, 2010 at 21:33 UTC | |
Re: Alternating Table Row Colors Help!
by Cody Fendant (Hermit) on May 06, 2010 at 00:48 UTC | |
by bradcathey (Prior) on May 06, 2010 at 01:43 UTC | |
Re: Alternating Table Row Colors Help!
by arc_of_descent (Hermit) on May 06, 2010 at 08:27 UTC |
Back to
Seekers of Perl Wisdom