This topic is locked
[SOLVED]

 Coloring cell conditional with events

7/26/2013 10:08:38 PM
PHPRunner General questions
G
gdude66 author

Hi

I am trying to shade a box with colours using the after record processed examples.

My sample code is below but I have syntax errors.

Does anyone know what I am doing wrong?



1. if ($data["Yr7 Sem1"]<4)

2. $record["Yr7 Sem1_style"].='style="background:red"';

3. if ($data["Yr7 Sem1"]<=4.25)

4. $record["Yr7 Sem1_style"].='style="background:yellow"';

5. else ($data["Yr7 Sem1"]>4.25)

6. $record["Yr7 Sem1_style"].='style="background:green"';

7. endif



Unexpected t variable line 6

Basically I want to have the background box red for a value below 4. yellow between 4 and 4.25 and green above 4.25
Also tried the following code in visual editor



if ($value<4.00)

$color="red";

if ($value >= 4.0 && $value <=4.25)

$color="green";

if ($value>4.25)

$color="blue";

$value="<font color='$color'>$value</font>";



That works for color but changes values like 4.25 to 4.250000 which is not going to work. Either want colored text but would prefer colored background.

B
bussb 7/28/2013

Here is what I use for my shaded background conditions, adapt as needed:
In the Events tab of PHPrunner for the List View, "List Page:After Record Processed"

if ($data["Status"]=="Open")

$record["Status_style"].='style="background:#ffff00"';


The field label is Status so replace this with whatever your field label is in your application. Add multiple if statements if you want more colors based on different field values. #ffff00 is the standard HEX color values, refer to HEX color pages such as http://www.colorschemer.com/online.html

G
gdude66 author 8/5/2013



Here is what I use for my shaded background conditions, adapt as needed:
In the Events tab of PHPrunner for the List View, "List Page:After Record Processed"

if ($data["Status"]=="Open")

$record["Status_style"].='style="background:#ffff00"';


The field label is Status so replace this with whatever your field label is in your application. Add multiple if statements if you want more colors based on different field values. #ffff00 is the standard HEX color values, refer to HEX color pages such as http://www.colorschemer.com/online.html



I now have this working by events using
if ($data["growth"]<"0")

$record["growth_style"].='style="background:#FF0000"';

if ($data["growth"]>="0"&& $data["growth"]<"0.2")

$record["growth_style"].='style="background:#FF9933"';

if ($data["growth"]>="0.2")

$record["growth_style"].='style="background:#00FF00"';

This produces red for values less than 0, orange for values between 0 and 0.2 and green for values greater than 0.2
Only problem is for no value it produces red as well. Any idea what I would put in if there were no value which would equal no color? eg stays default cell color? It is a calculated field so if the second or first cell has no value then no value will appear in the growth column.

C
copper21 8/5/2013



I now have this working by events using
if ($data["growth"]<"0")

$record["growth_style"].='style="background:#FF0000"';

if ($data["growth"]>="0"&& $data["growth"]<"0.2")

$record["growth_style"].='style="background:#FF9933"';

if ($data["growth"]>="0.2")

$record["growth_style"].='style="background:#00FF00"';

This produces red for values less than 0, orange for values between 0 and 0.2 and green for values greater than 0.2
Only problem is for no value it produces red as well. Any idea what I would put in if there were no value which would equal no color? eg stays default cell color? It is a calculated field so if the second or first cell has no value then no value will appear in the growth column.


Try this:
if ($data["growth"]<"0")

{

$record["growth_style"].='style="background:#FF0000"';

}

elseif ($data["growth"]>="0"&& $data["growth"]<"0.2")

{

$record["growth_style"].='style="background:#FF9933"';

}

elseif ($data["growth"]>="0.2")

{

$record["growth_style"].='style="background:#00FF00"';

}

else

{

}
This will take what you have and if the value is anything other than what you have specified, the background color will be default.
Brian

G
gdude66 author 8/5/2013



Try this:
if ($data["growth"]<"0")

{

$record["growth_style"].='style="background:#FF0000"';

}

elseif ($data["growth"]>="0"&& $data["growth"]<"0.2")

{

$record["growth_style"].='style="background:#FF9933"';

}

elseif ($data["growth"]>="0.2")

{

$record["growth_style"].='style="background:#00FF00"';

}

else

{

}
This will take what you have and if the value is anything other than what you have specified, the background color will be default.
Brian



Thanks. That didn't do the trick but setting a lower negative boundary did on the first if statement.