Re: Re: alternating colors
| From: | Matthew Leingang | Date: | Thu, 26 Oct 2000 19:35:16 +0000 |
| Subject: | Re: Re: alternating colors | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22195@lists.php.net to get a copy of this message | ||
Your solution would alternate colors one red, one blue, one red, one
blue...
Rodney was asking for _three_ red, three blue, three red, three
blue...which is a little trickier. There might be a simpler function
foo(), but I didn't check. For instance, I don't know how % behaves when
you give it a number that isn't an integer.
Later,
Matt
----------------------------------------------------------------
Matthew Leingang http://www.math.rutgers.edu/
Rutgers University leingang@math.rutgers.edu
Department of Mathematics "This signature needs no quote."
On Wed, 25 Oct 2000, Philip Hallstrom wrote:
> Couldn't you shorten that and do...
>
> $colors = array("red","blue");
>
> echo "<table>\n";
> for ($i = 0; $i < 100; $i++) {
> $j = $i % 2;
> printf("<tr bgcolor=%s><td>Row %s (color
> #%s)</td></tr>\n",
> $colors[$j],$i,$j);
> }
> echo "</table>\n";
>
> -philip
>
> In article <Pine.GSO.4.02A.10010231023590.18191-100000@lagrange.rutgers.edu> you write:
> >Hi Rodney,
> >
> >This works:
> >
> ><?php
> >
> >function foo($n) {
> > $mod = 3;
> > return ((($n % (2*$mod)) / $mod ) < 1);
> >}
> >
> >$colors = array("red","blue");
> >
> >echo "<table>\n";
> >for ($i = 0; $i < 100; $i++) {
> > $j = foo($i);
> > printf("<tr bgcolor=%s><td>Row %s (color
> > #%s)</td></tr>\n",
> > $colors[$j],$i,$j);
> >}
> >echo "</table>\n";
> >
> >?>
> >
> >
> >----------------------------------------------------------------
> >Matthew Leingang
> >http://www.math.rutgers.edu/
> >Rutgers University leingang@math.rutgers.edu
> >Department of Mathematics "This signature needs no quote."
> >
> >On Thu, 19 Oct 2000, Rodney Davis wrote:
> >
> >> I am trying to alternate table bgcolor with each iteration of
> >> the following loop:
> >>
> >> print
> >>
> >> "<td><b>One</b></td>\n<td><b>Two</b></td>\n<td><b>Three</b></td>\n</tr>";
> >> foreach ($list as $row)
> >> {
> >> print "<tr>\n";
> >> print "<td> $row[one] </td>\n<td> $row[two] ";
> >> print " </td>\n<td> $row[three]
> >> </td>\n</tr>\n<tr><td colspan=3>
> >> $row[four] </td>\n</tr>\n";
> >> print "<tr>\n<td colspan=3> $row[five] </td>\n";
> >> print "</tr>\n";
> >> }
> >> print "</table>";
> >>
> >> So that every three rows will be a single grouped color different from the
> >> next three rows.
> >> Does anyone know how to do this ?
> >>
> >> Thanks
> >>
> >> rodney