for loop + groupings
Posted: Sat May 08, 2010 6:57 pm
Hi there- Question for you. I have a simple for loop that writes table data to a web page. What I would like to do is group some of the data by similarity and alter the background color for each group. For visual instance:
2010
2010
2010
2009
2009
2008
2008
2008
I'm wondering if I need to push each group into an array, and then change the color of the even numbered indices. How might I push those groups into an array? Thanks any help is appreciated!
2010
2010
2010
2009
2009
2008
2008
2008
I'm wondering if I need to push each group into an array, and then change the color of the even numbered indices. How might I push those groups into an array? Thanks any help is appreciated!
Code: Select all
for($i=0;$i<$total;$i++)
{
$row = mysql_fetch_object($result);
$year=$row->db_year;
<table>
<tr>
<td <? if($year == $year)
echo 'bgcolor = "#cccccc"'; ?>>
<?= $year == "" ? " " : $year; ?>
</td>
</tr>
</table>
}