Click to See Complete Forum and Search --> : aternate table row colors


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>

NightShift58
02-06-2007, 11:40 PM
You're slacking off on me...<?php
while($r = mysql_fetch_array($sql_get_ads)){

$row_color = ($row_count++ % 2) ? $color1 : $color2;
?>
<tr>
<td bgcolor="<?php echo $row_color ?>"><div align="center"><img src="adImages/<?php echo $r['image']; ?>" height="40" width="40"/></div></td>
<td bgcolor="<?php echo $row_color ?>"><div align="center"><a href="#"><?php echo $r['title']; ?></a></div></td>
<td bgcolor="<?php echo $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
}
?>

kproc
02-06-2007, 11:51 PM
I should go to bed. thanks :)

NightShift58
02-07-2007, 01:31 AM
And so am I...<?php
$thirty_days = 30 * 24 * 60 * 60;
while($r = mysql_fetch_array($sql_get_ads)){
?>
<tr bgcolor="<?php echo (($row_count++ % 2) ? $color1 : $color2) ?>">
<td><div align="center"><img src="adImages/<?php echo $r['image']; ?>" height="40" width="40"/></div></td>
<td><div align="center"><a href="#"><?php echo $r['title']; ?></a></div></td>
<td><div align="center"><?php echo $r['price']; ?></div></td>
<td><div align="center"><? echo date("Y-m-d", strtotime($r['ad_date']) + $thirty_days); ?></div></td>
</tr>
<?php
}
?>

bokeh
02-07-2007, 08:21 AM
<tr bgcolor="<?php echo (($row_count++ % 2) ? $color1 : $color2) ?>">That can also be written like this:($i^=1)But I digress, that is proprietary mark-up and should never be used. Don't put style information directly in an HTML document; just put the hooks so it can be controlled from the stylesheet.

NightShift58
02-08-2007, 02:18 AM
Never used ^ in all the years. I like it...