Question: I want to change the colour of td dynamically, 
Here is my code:

```
<td>
<?php 
    if($status === 'On time'){
        $color = "green";
    }elseif ($status === 'No data') {
        $status = "Address Not Found";
        $color = "red";
    }else{
        $status = "Free Slot";
        $color = "grey";
    }
?>
<?php echo $status; ?>
<?php

}

?>

</td>

```

I want to change the colour of the td depends on the status I received from PHP side.

So how to Dynamically add colour to td?

Answer: 
You should set color as variable somewhere before output and then print it as bgcolor or css (style="background-color:#...") property inside "td" tag. Simple solution:

```
<?php
    $color = "#000000"; //set color before output
?>
...
<td bgcolor="<?=$color?>"></td> <!--short php variable output inside html code -->

```

Result: 

```
<td bgcolor="#000000"></td>

```
Try this

```
<?php 
$status = 'On time';
if ($status === 'On time'){
    $color = "green";
} elseif ($status === 'No data') {
    $status = "Address Not Found";
    $color = "red";
} else {
    $status = "Free Slot";
    $color = "grey";
}
?>
<table>
    <tr>
        <td style="background-color: <?php echo $color; ?>"><?php echo $status; ?></td>
    </tr>
</table>

```