I'm working on a corporate website in which you retrieve (via a MySQL consult) some data that are formatted on a HTML table. The problem comes when trying to change the row color if a specific field value is one or another.
The (partial) code is:
$RowCt = 0;
while($Row = mysql_fetch_assoc($Result))
{
$timezone = new DateTimeZone( "Europe/London" );
$date = new DateTime();
$date->setTimezone( $timezone );
$ahora = $date->format( 'H:i' );
if ($var == 1) {
$rowcolor = "red";
} else if ($var == 0) {
$rowcolor = "yellow";
} else {
$rowcolor = "white";
}
//$Table.= "<tr style='background-color:#FFFFFF;'>";
foreach($Row as $field => $value)
{
switch ($field) {
default:
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>$value</td>";
break;
case a:
if ($now > $value) {
$var == 0;
} else {
// Do nothing
}
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>$value</td>";
break;
case b:
if ($now > $value) {
$var == 1;
} else {
// Do nothing
}
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>$value</td>";
break;
case c:
switch ($value) {
case 1:
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>a</td>";
break;
case 2:
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>b</td>";
break;
}
case d:
switch ($value) {
case 3:
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>a</td>";
break;
case 4:
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>b</td>";
break;
case 5:
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>c</td>";
break;
case 6:
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>d</td>";
break;
}
case e:
switch ($value) {
case "E":
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>a</td>";
break;
case "I":
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>b</td>";
break;
case "F":
$Table.= "<td style='font-size:14px; background-color:$rowcolor' align='center'>c</td>";
break;
}
}
}
$Table.= "</tr>";
The problem comes when trying to define a value inside of the switch statement, and then trying to make it be a condition so the entire row is colored (yellow if case 1 is selected and we aren't on time; red if case 2 is selected and we aren't on time).