-1

My 4th column produces two outputs from the PHP that is "complete" and "pending". I want to set a condition that will change "complete" to green, the default color is set to red since default content is "pending". i.e The text color.

<tr>
  <th scope="row"><?php echo $array[0];?></th>
  <td><?php echo $array[1];?></td>
  <td><?php echo $array[2];?></td>
  <td><?php echo $array[3];?></td>
  <td class="status" style="color: red;"><?php echo $array[4];?></td>

A jquery code would be much appreciated.

DarkBee
  • 16,592
  • 6
  • 46
  • 58

1 Answers1

1

Use ternary operator to check the condition

<?php $color = ($status == 'complete') ? 'green' : red; ?>
<tr>
  <th scope="row"><?php echo $array[0];?></th>
  <td><?php echo $array[1];?></td>
  <td><?php echo $array[2];?></td>
  <td><?php echo $array[3];?></td>
  <td class="status" style="color:<?php echo $color; ?>;"><?php echo $array[4];?></td>
</tr>
Yogendra
  • 1,208
  • 5
  • 18
  • 38