RE: [PHP] alternating colors
| From: | Mark Olbert | Date: | Fri, 20 Oct 2000 00:07:12 +0000 |
| Subject: | RE: [PHP] alternating colors | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21306@lists.php.net to get a copy of this message | ||
Try this:
$colors = array("red", "blue", "green");
$curcolor = 0;
foreach ($list as $row)
{
<td bgcolor=$colors[$curcolor]>....</td>
$curcolor++;
if( $curcolor >= count($colors) ) $curcolor = 0;
}
Please note that I may have messed up the syntax on the array function and
the if statement; I sometimes get confused between php, perl, and a bunch of
other scripting languages that I use <grin>.
You'll have to adapt the code fragment to output your particular table, of
course. But the basic idea is to us the bgcolor attribute of the <td> tag,
and cycle thru an array of allowable colors.
For speed optimization you might assign count($colors) to a variable, since
it doesn't change within the loop.
Good luck!
- Mark
-----Original Message-----
From: Rodney Davis [mailto:rodney@wincubic.com]
Sent: Thursday, October 19, 2000 4:33 PM
To: php-general@lists.php.net
Subject: [PHP] alternating colors
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
--
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