This topic is locked

How to change row background color programmatically

10/4/2007 7:03:58 AM
PHPRunner Tips and Tricks
admin

PHPRunner 4.2

For this purpose use After Record Processed event:
To change row background color use the following:

$row["rowstyle"]='style="background:blue"';


To change any cell background color use the following:

$row[$col."FieldName_style"]='style="background:red"';


PHPRunner 5.0/5.1/5.2

For this purpose use After Record Processed event:
To change row background color use the following:

$row["rowstyle"]='style="background:blue"';


To change any cell background color use the following:



$record["FieldName_style"]='style="background:red"';

vin7102 2/21/2009

Code works great,

can you do the same with the font color instead of the background color?

ficcionista 4/7/2009

Code works great,

can you do the same with the font color instead of the background color?



I haven't had the chance to try it out, but i believe it would work like this:
[codebox]global $record;

$record["FieldName_style"]='style="color:red"';[/codebox]

[codebox]$row["rowstyle"]='style="color:blue"';[/codebox]
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=39902&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />

vin7102 4/17/2009

Ficc,
It works great, Thanks

R
run4sbc 4/22/2009

What if I wanted to change the color based on the data in the field....
For instance make the row pink when Gender=Female or blue when Gender=Male

admin 4/22/2009

run4sbc,

if ($data["Gender"]=="Male")

$row["rowstyle"]='style="background:blue"';

else

$row["rowstyle"]='style="background:pink"';


I believe you only have two genders in the database so this code should be enough.

R
Ravengaard 5/7/2009

How would I go about this if I would like to use it to center the text in a column?

I have tried this:

if ($data["Kommentar"]=="")

;

else

$row["rowstyle"]='style="text-align:left"';


Without any luck.
Fixed it, with this code:

global $record;
if ($data["Kommentar"]=="")

;

else

$record["Kommentar_style"]='style="text-align:left"';
T
thiethie17 10/24/2009

hello,

i am a french user of phprunner 5.1

my problem is:
the solution you explain in this post is works great for:
global $record;

$record["FieldName_style"]='style="color:red"';
but i have nothing great for :

$row["rowstyle"]='style="background:blue"';
no change !!!! nothings !! i would like to change the color : the full line (all fields ) when the conditions is true !!

thanks for for help !!
Thierry

T
thiethie17 10/24/2009

i make on error
it's works wery well thanks !!
thierry

C
capp 1/2/2010

I'm not seeing the change take place, my code is as follows:
global $record;
if ($values["STATUS"]=="INSTALL")

{

$record["status_style"]='style="background:red"';

}
... also, for the status field I have it set as a lookup wizard with 'install' set as one of the options.
thanks

vin7102 1/3/2010



I'm not seeing the change take place, my code is as follows:
global $record;
if ($values["STATUS"]=="INSTALL")

{

$record["status_style"]='style="background:red"';

}
... also, for the status field I have it set as a lookup wizard with 'install' set as one of the options.
thanks



Cappa,
Try this:

global $record;

if ($data["STATUS"]=="INSTALL") //---Replace $values with $data and Be careful with your case, These values are Case Sensitive---
$record["STATUS_style"]='style="background:red"';


Vince

C
capp 1/3/2010



Cappa,
Try this:

global $record;

if ($data["STATUS"]=="INSTALL") //---Replace $values with $data and Be careful with your case, These values are Case Sensitive---
$record["STATUS_style"]='style="background:red"';


Vince


Hi Vince,
I've used what you suggested(on the After Record Updated Events Page), and it states: Undefined variable: data.

The function for AfterEdit does not pass $data as a parameter. Which is why I've tried $values but to no avail.
any other thoughts on this?
Thanks.

vin7102 1/4/2010

Cappa,
Sorry about that, I thought this was a list page event, I realize now that you need this in an edit page.

I don't have a solution but I'll keep trying. Hopefully support will chime in soon!
Good luck,

Vince

S
slodigia_lem 1/8/2010



Hi Vince,
I've used what you suggested(on the After Record Updated Events Page), and it states: Undefined variable: data.

The function for AfterEdit does not pass $data as a parameter. Which is why I've tried $values but to no avail.
any other thoughts on this?
Thanks.



Hello Vince, I have tried several time to change the font color w/o sucess. I succeded to change the background color,

the font style but no way to change the color. I am using php runner 5.1 with this code:
if(($data['ABCCode'] == "A") or ($data['ABCCode'] == "A+"))

{

$row["rowstyle"]='style="font-style:italic;"'; <------- WORK PERFECT

if($data['CurrentPosition'] <0)

{

//$row["rowstyle"]='style="background:blue"';

//$row['rowstyle']='style="color:red"'; <---------- NOT WORKING

$row["rowstyle"]='style="font-weight:bold;font-style:italic;"'; <------- WORK PERFECT
} // end if current < 0

} // end if A style
Can be because I am not using the default color schema? Did someone had the same issue?
Thanks

Stefano

F
forceDevClub member 5/18/2010



Hello Vince, I have tried several time to change the font color w/o sucess. I succeded to change the background color,

the font style but no way to change the color. I am using php runner 5.1 with this code:
if(($data['ABCCode'] == "A") or ($data['ABCCode'] == "A+"))

{

$row["rowstyle"]='style="font-style:italic;"'; <------- WORK PERFECT

if($data['CurrentPosition'] <0)

{

//$row["rowstyle"]='style="background:blue"';

//$row['rowstyle']='style="color:red"'; <---------- NOT WORKING

$row["rowstyle"]='style="font-weight:bold;font-style:italic;"'; <------- WORK PERFECT
} // end if current < 0

} // end if A style
Can be because I am not using the default color schema? Did someone had the same issue?
Thanks

Stefano


Not working for me tried all modes.

the background don't change.

S
slodigia_lem 5/19/2010



Not working for me tried all modes.

the background don't change.


Can u post the code? The background works fine, the font color has never worked to me as well

greggk 7/27/2010

I've tried many different ways of changing the background, and I keep getting an error "undefined variable: data"

On the list page, I want to change the background of a field to RED if a condition applies.

So, if data_1 = or > 1000 I want field data_2 background to be red.

This is what I've tried.
global $record;

if ($data["data_1"]=="1000")

$record["data_2_style"]='style="background:red"';
what exactly am I doing wrong?

Oh, and I'm adding this code in the list page EVENTS, and I tried both "before display" and "fetch records"

Maybe that's where my problem lies. I don't know.

I have also tried using it "After Record Processed" With that one I get no error, but the background color does not change either.
I just noticed something. When editing the record and going back to the list page, when it's loading, just for a split second the background of the field does turn red, but it reverts back to original color.

greggk 7/28/2010

I think the code is correct, it was my version, I was still running the beta version, I updated to the latest version, and I believe it's working no <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=51437&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

greggk 7/29/2010

I have run into a new problem with the changing of the background.

On the list page, I wanted to change the cell background red, if an amount is higher than or equal to 1000.

It works great for the 1st data entry. If you add a second data entry with the amount less than 1000, then both the first and second lines show up with no red background.

If both data entries are over 1000, then it's fine again, both cells turn red.

Here is the code.
if ($data["Bid_1"]>="1000")

$record["Bid_1_style"]='style="background:red"';
Also, if I add global record: on top, it doesn't work at all.

I'm running the lastest 5.2 version of PHPrunner.

greggk 7/29/2010

Never mind. It seemed like the beta version of 5.2 had some issues. I started from scratch, created the database from scratch with the latest release version, and it's working just like it's supposed to :-D

D
Death 1/8/2011

DOESN'T WORK IN FIREFOX!!!!!!!!!!!!!!!!
How is this done so it works in Firefox?

T
tedwilder 4/14/2011

_

ficcionista 5/17/2011



Hello Vince, I have tried several time to change the font color w/o sucess. I succeded to change the background color,

the font style but no way to change the color. I am using php runner 5.1 with this code:
if(($data['ABCCode'] == "A") or ($data['ABCCode'] == "A+"))

{

$row["rowstyle"]='style="font-style:italic;"'; <------- WORK PERFECT

if($data['CurrentPosition'] <0)

{

//$row["rowstyle"]='style="background:blue"';

//$row['rowstyle']='style="color:red"'; <---------- NOT WORKING

$row["rowstyle"]='style="font-weight:bold;font-style:italic;"'; <------- WORK PERFECT
} // end if current < 0

} // end if A style
Can be because I am not using the default color schema? Did someone had the same issue?
Thanks

Stefano



Hi,
you're not using the correct PHP operator.
Here:

if(($data['ABCCode'] == "A") or ($data['ABCCode'] == "A+"))



You should use "||" instead of "OR".

T
tedwilder 5/18/2011

_

U
unsearcheable 6/17/2011

I am placing code :

global $record;

if ($data["field"]=="17-06-2011");

else

$record["field_style"]='style="text-align:left"';


It works !

S
stec5345 8/7/2011

How about in the instance where the cell color would change to Red if the datetime or just date field is, lets say, greater than 30 days?
Stevec