i am trying to change the color of a td element in a table based on the statusID. status can be either zero or one. I wanna show the td as red if it its status is zero and green if status is one. my code doesn't work. I am getting the status of the device to a variable calle $statusDevice. any suggestions are welcomed.
$colors = [ '#FF0000',' #008000'];
$conn= mysqli_connect( $dbhost, $dbuser, $dbpass, $db ) or die("Could not connect: " .mysqli_error($conn) );
$sql = "SELECT Name FROM parameter WHERE Device='A'";
if($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0){
echo '<table>';
while($row = mysqli_fetch_array($result)){
$bgColor= $colors[$statusDevice];
echo $bgColor;
//echo $colors[0];
echo '<tr><th>Status of Device</th>';
echo '<td bgcolor= $bgColor); >' . $row['A']. '</td></tr>';
echo $bgColor;
}echo "</table>";
}
$statusDevicedeclared?bgcoloris deprecated. Instead usestyleas @ChrisS. suggested