Re: alternating colors

From: Date: Mon, 23 Oct 2000 14:25:59 +0000
Subject: Re: alternating colors
Groups: php.general 
Request: Send a blank email to php-general+get-21870@lists.php.net to get a copy of this message
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" ] >

« previous php.general (#21870) next »