note 58648 deleted from control-structures.while by philip
| From: | philip@php.net | Date: | Thu, 27 Apr 2006 15:51:18 +0000 |
| Subject: | note 58648 deleted from control-structures.while by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109863@lists.php.net to get a copy of this message | ||
Note Submitter: belmaati at gmail dot com
----
Here's a small example on how to make alternating row colors using a while loop and the modulo
operator.
<?php
$array = range(1, 20);
print '<table align="center" width="90%" cellspacing="1"
cellpadding="3" border="0">';
while(current($array))
{
print '<tr>';
if (key($array) % 2)
{
print '<td bgcolor="#EEEEEE" style="font: 10px verdana;">'
. str_repeat(current($array), 10) . '</td>';
}
else
{
print '<td bgcolor="#CCCCCC" style="font: 10px verdana;">'
. str_repeat(current($array), 10) . '</td>';
}
print '</tr>';
next($array);
}
print '</table>';
?>