Question: I have if conditions that display depending on the value in sql database column.
What I am trying to achieve is to have different colors for each output. This is my code

```html
<?php $statusshow  = $row0["accStatus"]?>
    <p>Status:> <?php
     if ($statusshow == "1") {echo "Pending Confirmation!";}
     elseif ($statusshow == "2") {echo "Confirmed!";}
     elseif ($statusshow == "3") {echo "Processing..";}
     elseif ($statusshow == "4") {echo "Declined";}                            
     ?></p>

```

I would like pending confirmation to be red, confirmed to be green, processing to be yellow and declined to be red. How can I achieve this?

Answer: 
To minimize codelines you can add a function which will return text message and style for provided input:

```
function getMessageAndColor($status) {
    if ($status == "1") {return ["Pending Confirmation!", "color: red;"];}
    elseif ($status == "2") {return ["Confirmed!", "color: green;"];}
    elseif ($status == "3") {return ["Processing..", "color: yellow;"];}
    elseif ($status == "4") {return ["Declined", "color: red;"];}
}

[$message, $color] = getMessageAndColor($row0["accStatus"]);?>
<p>Status:<span style="<?=$color?>"><?=$message?></p>

```
Set variables in the `if` statements for the color and message. Then use the variables when you echo the span.

```
$<php
$statusshow  = $row0["accStatus"];
if ($statusshow == "1") {
    $message ="Pending Confirmation!";
    $color = "red";
} elseif ($statusshow == "2") {
    $message ="Confirmed!";
    $color = "green";
} elseif ($statusshow == "3") {
    $message ="Processing..";
    $color = "yellow";
} elseif ($statusshow == "4") {
    $message ="Declined";
    $color = "red";
}
?>
<p>Status:<span style="color: <?php echo $color; ?>;"> <?php echo $message; ?></span></p>

```