Re: Re: alternating colors
| From: | Philip Hallstrom | Date: | Wed, 25 Oct 2000 20:36:06 +0000 |
| Subject: | Re: Re: alternating colors | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21923@lists.php.net to get a copy of this message | ||
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
>>
>>
>>
>> [ Part 61: "Included Message" ]
>>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>