October 28th, 2013, 03:35 PM
-
Alternating Background Table
Hello
I'm hoping someone can help me work out whats wrong. I've been looking at this for a while now and just can't see what I'm doing wrong. I'm sure it's something simple I'm overlooking:
Code:
$days = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
echo '<table class="table">';
echo '<tr><td style="width: 25%;"></td><td style="width: 25%;">Class Name</td><td style="width: 25%;">Start - End Time</td><td style="width: 25%;">Class Type</td></tr>';
$c=0;
foreach($days as $day) {
$postcolour = $c % 2 ? '#000;' : '#dd3134;;
$query = mysql_query("SELECT * FROM classes WHERE userid = '$id' AND day = '$day'") or die(mysql_error());
if(mysql_num_rows($query) > 0) {
$i=0;
while($fetch = mysql_fetch_array($query)) {
$day = ($i == 0 ? $day : '');
echo '<tr style="background-color: '.$postcolour.'"><td style="width: 25%;">'.$day.'</td><td style="width: 25%;">'.$fetch['classname'].'</td><td style="width: 25%;">'.$fetch['start'].' - '.$fetch['end'].'</td><td style="width: 25%;">'.ucfirst($fetch['type']).'</td></tr>
';
$i++;
}
} else {
echo '<tr style="background-color: '.$postcolour.'"><td>'.$day.'</td><td colspan="3"><i>No classes</i></td></tr>';
}
$c++;
}
echo '</table>';
Basically, the problem is, it's not setting the background colour to #dd3134, but it is displaying the black #000 rows correctly.
Can anyone help?
Many thanks
Last edited by stevenatherton4; October 28th, 2013 at 03:57 PM.
October 28th, 2013, 03:57 PM
-