kproc
02-06-2007, 11:35 PM
Hi, the below is supposed to alternate colors for each row, its not working. I got the initial script from a tutorial I found doing a google seach
<table class="forms">
<tr>
<td colspan="5" class="header">
Search Results </td>
</tr>
<tr>
<td><div align="center"></div></td>
<td><div align="center">Item Title </div></td>
<td><div align="center">Price</div></td>
<td><div align="center">End Date </div></td>
</tr>
<?php
$color1 = "#CCFFCC";
$color2 = "#BFD8BC";
$row_count = 0;
while($r = mysql_fetch_array($sql_get_ads)){
$row_color = ($row_count % 2) ? $color1 : $color2; ?>
<tr>
<td bgcolor="$row_color"><div align="center"><img src="adImages/<?php echo $r['image']; ?>" height="40" width="40"/></div></td>
<td bgcolor="$row_color"><div align="center"><a href="#"><?php echo $r['title']; ?></a></div></td>
<td bgcolor="$row_color"><div align="center"><?php echo $r['price']; ?></div></td>
<td><div align="center">
<?php $date_array = explode("-",$r['ad_date']);
$ad_date = mktime(0, 0, 0, $date_array[1], $date_array[2]+30, $date_array[0]);
$end_date = date("Y-m-d", $ad_date);
echo $end_date;
?>
</div>
</td>
</tr>
<?php $row_count++; ?>
<?php } ?>
</table>
<table class="forms">
<tr>
<td colspan="5" class="header">
Search Results </td>
</tr>
<tr>
<td><div align="center"></div></td>
<td><div align="center">Item Title </div></td>
<td><div align="center">Price</div></td>
<td><div align="center">End Date </div></td>
</tr>
<?php
$color1 = "#CCFFCC";
$color2 = "#BFD8BC";
$row_count = 0;
while($r = mysql_fetch_array($sql_get_ads)){
$row_color = ($row_count % 2) ? $color1 : $color2; ?>
<tr>
<td bgcolor="$row_color"><div align="center"><img src="adImages/<?php echo $r['image']; ?>" height="40" width="40"/></div></td>
<td bgcolor="$row_color"><div align="center"><a href="#"><?php echo $r['title']; ?></a></div></td>
<td bgcolor="$row_color"><div align="center"><?php echo $r['price']; ?></div></td>
<td><div align="center">
<?php $date_array = explode("-",$r['ad_date']);
$ad_date = mktime(0, 0, 0, $date_array[1], $date_array[2]+30, $date_array[0]);
$end_date = date("Y-m-d", $ad_date);
echo $end_date;
?>
</div>
</td>
</tr>
<?php $row_count++; ?>
<?php } ?>
</table>