Hi, I'm changing the color of the text in the table according to its value... if the value is "posted" then its color is blue if it's "cancel" it's red...
I have been able to achieve it using an if statement:
<td><span style="<?php if($value['posted'] == 'posted')echo 'color:blue'?>"><?php echo $value['posted']; ?></span></td>
When I add an ELSE IF for the cancel I figured out that it should look like this;
<td><span style="<?php
if($value['posted'] == 'posted')
{
echo 'color:blue'
}
else if($value['posted'] == 'cancel')
{
echo 'color:red'
}
?>">
<?php echo $value['posted']; ?></span></td>
But it's SYNTAX ERROR UnEXPECTED }
I know it's just a simple else if statement but I can't get it right. Please help...
You need semicolons after your echo
:
if($value['posted'] == 'posted')
{
echo 'color:blue';//<-- right here
}
else if($value['posted'] == 'cancel')
{
echo 'color:red';//<-- right here
}
The most efficient (albeit a little complicated) way to do this will be with a ternary inside a PHP shorttag:
<td><span style="<?= $value['posted'] == 'posted' ? 'color: blue' : ($value['posted'] == 'cancel' ? 'color: red' : '') ?>">
<?= $value['posted'] ?></span></td>