Re: Making alternate rows of different colour
| From: | Chris Hayes | Date: | Fri, 17 Jan 2003 11:35:20 +0000 |
| Subject: | Re: Making alternate rows of different colour | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-131986@lists.php.net to get a copy of this message | ||
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) {$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.echo '<tr bgcolor="'.$cols[$i%2].'"><td>$row_data</td></tr>';} um, Rasmus, shouldn't this have a