Forum Moderators: coopster
<table cellpadding="0" cellspacing="0" id="models">
<tr class="headings">
<th class="model">Model</th>
<th class="weight">Weight</th>
<th class="price">Delivered</th>
<th class="price">10 Miles</th>
<th class="price">15 Miles</th>
<th class="price">20 Miles</th>
</tr>
<?php
$color1 = "#CCFFCC";
$color2 = "#BFD8BC";
$row_count = 0;
?>
<? while($row=mysql_fetch_array($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<tr style="background-color:<? $row_color ?>;">
<td><?=$row['model_name']?></td>
<td><?=$row['model_weight']?>kg</td>
<?php
$subtotal = sprintf("%.2f", ($row['model_weight'] / 1000) * $price);
$total = floor($subtotal);
if ($total > 0) {
$total10 = $total - 30;
$total15 = $total - 40;
$total20 = $total - 50;
}
else
{
$total10 = $total;
$total15 = $total;
$total20 = $total;
}
?>
<td>£<? echo $total ?></td>
<td>£<? echo $total10 ?></td>
<td>£<? echo $total15 ?></td>
<td>£<? echo $total20 ?></td>
</tr>
<?
$row_count++;
} ?>
</table>
A good habit is to apply your colors to the cells, not rows, what if you have a column on the far right for subtotal that's a different color? :-)
$row_color = ($row_color==$color1)? $color2:$color1;
<style>
.ri {background-color:green;}
.triple {color:red;}
.six {color:blue;}
</style>
<?php
$l = '';
$ri = 0;
foreach (range(1,9) as $v) {
$o = str_repeat($v, 20); // pad it up to expand our cell a bit ;-)
$class = array();
$class[] = $ri++ & 1 ? '' : 'ri';
// more code here, maybe adding more classes; example:
if (!($v % 3)) {
$class[] = 'triple';
}
$classTD = $v == 6 ? ' class="six"' : ''; // special cell coloring
$class = array_unique(array_filter($class));
$class = $class ? ' class="' . implode(' ', $class) . '"' : '';
$l .= " <tr{$class}><td>Value: </td><td{$classTD}>{$o}</td></tr>\n";
}
print "<table>\n{$l}</table>";
exit;
?>