Forums

Conditional text formatting

elsepu 03 Apr, 2010
Is there a way to change the text formatting depending on the returned value from the database? I'm using CC to display a table where one of the cells returns either "Approved," "Declined" or "Pending." I would like to display this values in different color if possible. I'm not well versed at PHP or JavaScript at all, so any help is appreciated. Thank you in advance.
GreyHead 04 Apr, 2010
Hi elsepu,

You are going to need to beg borrow or buy a little coding skill to do this.

The variables are available to you in a data object $MyRow and you can get the values of individual items with $MyRow->item_name

So if you have a 'result' item then you might set the style like this:
<?php
switch ($MyRow->result ) {
  case 'Approved' :
    $color = 'green';
    break;  
  case 'Declined' :
    $color = 'red';
    break; 
  case 'Pending' :
    $color = 'orange';
    break;
  default:
    $color = 'black';
    break;
}
echo "<div style='color: $color;'>".$MyRow->result."</div>";
?>

Bob
elsepu 05 Apr, 2010
GreyHead, this worked perfectly! Thank you so much.

I have been a fan of your posts for a long time and wanted to take this opportunity to thank you for your dedication to this forum. I have truly learned so much!

Alex Sepulveda
GreyHead 06 Apr, 2010
Hi Alex,

Thank you, much appreciated.

Bob
This topic is locked and no more replies can be posted.