This topic is locked
[SOLVED]

Conditional Formatting using HEX

11/24/2024 6:47:52 AM
PHPRunner General questions
P
PK author

I am trying to change the background color of a cell on a list page based on its value. Possible values are between 1 and 5 so I have a table that has these values with corresponding hex color code to apply to the cells with that value.
Then I am trying to apply the color on the List page: After Record Processed event:

$color = "#FF0000";//DB::DBLookup("select BackColor from appraisal_ranking WHERE RankName = '".$data["Ranking"]."'");
$colorcode = "'"."background-color:".$color."'";
$record["Ranking_css"].=$colorcode;

It does not work. When I hard code the color like this

$record["Ranking_css"].='background-color:#FF0000';

it works. But as the color of each value can be set by the user from another page, I need to lookup the color, not hard code it.
Finally when I echo $colorcode, I get the correct value: 'background-color:#FF0000'
What am I missing?

C
cristi 11/24/2024

Why so many single and double quotes???
And if you use concatenation in $colorcode why do you use it again in $record???

So:

$color = "#FF0000";//DB::DBLookup("select BackColor from appraisal_ranking WHERE RankName = '".$data["Ranking"]."'");
$colorcode = "background-color:".$color;
$record["Ranking_css"].=$colorcode;
P
PK author 11/25/2024

Thank you cristi. Spot on as usual. I assumed that becuase the hardcoded code had the single quotes I somehow needed them in there for it to work