At 09:05 17-1-2003, you wrote:
> I put the output of the database query in a table. It works fine. Now I have a need to make the alternate rows of a different color.
>
> Can someone please help me with the code?

$cols = array('#ff0000','#00ff00');
$i = 0;
while(your_loop_to_output_each_row) {
echo '<tr bgcolor="'.$cols[$i%2].'"><td>$row_data</td></tr>';
}
um, Rasmus, shouldn't this have a
$i++;
line in the while loop?


some other ways (there are many)

- shortest code, you need to use a 'for' loop or add a counter $i that is increased in every loop

for ($i=0; $i<=10; $i++)
{ echo '<tr bgcolor="'.(($i%2==0)?'red':'white')."\"><td>$i</td></tr>";
}


- using a color toggle

$color_toggle=false;
for ($i=0;$i<10;$i++)
{
echo('<TR bgcolor="'.(($color_toggle=!$color_toggle)?'#D8D1E7':'white')
}

Of ocurse you can put the color values in variabels like $color1 and $color2, and define them at the top of the file for easier configuring.






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to