This topic is locked

Change text color of elements in a list display?

10/30/2006 6:49:10 PM
PHPRunner General questions
W
wclaren author

Hi All --
Is there a way to change the text color of an element in a list display based on the value of that

element? For example if the value of "1" was ACTIVE could the text for ACTIVE be green and if

the value of "2" was INACTIVE could the text color be red for INACTIVE ?

J
Jane 10/31/2006

Hi,
sure. You can do it using Custom option on the "Vies as" settings dialog on the Visual Editor tab.

Here is a sample code:

if ($value==1)

$value = "<font color=green>".$value."</font>";

if ($value==2)

$value = "<font color=red>".$value."</font>";

M
markdorminy 11/1/2006

How would one do this for a value contained in an output row in 3.1?

Admin 11/1/2006

Hi,
the instructions above are for PHPRunner 3.1

M
markdorminy 11/1/2006

$value is not working... in fact, the custom code doesn't seem to be included anywhere. What am I missing?

Admin 11/1/2006

Open List or View page in Visual Editor in PHPRunner, double-click your field, choose Custom in the dialog and enter the expression suggested.

M
markdorminy 11/1/2006

Yep. Still not working. I can't find the script where the custom code has been incorporated, either.

M
markdorminy 11/1/2006

A thousand pardons, Alexey... it does work just as you said. I was trying to color a lookup field. By the way, how can one do that?

Admin 11/1/2006

To color lookup field on the list page you'll need to modify generated list page.
Apply the same login to open <font color=...> tag before field value is displayed and close it after that.

M
markdorminy 11/2/2006

I was afraid you'd say that.
Thanks for the great support!!!

MD

G
gdude66 11/12/2006

To color lookup field on the list page you'll need to modify generated list page.

Apply the same login to open <font color=...> tag before field value is displayed and close it after that.


Can this be explained a little further as I can't see where to change the colour for the lookup values in the list page. The list page values are filled elsewhere but only appear as text in the list page.

Admin 11/13/2006

Graeme,
to add a conditional coloring to your lookup fields you need to modify generated ..._list.php file.
Find ths snippet there:

if($lookuprow=db_fetch_numarray($rsLookup))

$value=ProcessLargeText($lookuprow[0],"","",MODE_LIST);

else

$value=ProcessLargeText(GetData($data,"FieldName", "..."),"field=FieldName".$keylink,"",MODE_LIST);



where FieldName is your actual field name.

Then add a coloring code just after. I.e.

if($data["FieldName"]>0)

$value = "<font color=red>".$value."</font>";

G
gdude66 11/13/2006

Graeme,

to add a conditional coloring to your lookup fields you need to modify generated ..._list.php file.
Find ths snippet there:
where FieldName is your actual field name.

Then add a coloring code just after. I.e.



Thanks - does this work in version 3.0?

Admin 11/13/2006

No, this workaround is for 3.1 only.
Here is the code snippet in ..._list.php you need to modify in version 3.0

if($lookuprow=db_fetch_numarray($rsLookup))

echo ProcessLargeText($lookuprow[0]);

else

echo ProcessLargeText(GetData($rsData,$data,"FieldName", "..."),$iquery);

G
gdude66 11/13/2006

No, this workaround is for 3.1 only.

Here is the code snippet in ..._list.php you need to modify in version 3.0


If value is used then the return is undefined variable? using

if($data["FieldName"]>0)

$value = "<font color=red>".$value."</font>";

G
gdude66 11/18/2006

Graeme,

to add a conditional coloring to your lookup fields you need to modify generated ..._list.php file.
Find ths snippet there:
where FieldName is your actual field name.

Then add a coloring code just after. I.e.



What does I.e. stand for?

Here is my code snippet and it makes all values red no matter what

if($lookuprow=db_fetch_numarray($rsLookup))

$value=ProcessLargeText($lookuprow[0],"","",MODE_LIST);

else

$value=ProcessLargeText(GetData($data,"progressid",
"Custom"),"field=progressid".$keylink,"",MODE_LIST);

if($data["progressid"]="1")

$value = "<font color=red>".$value."</font>";

}

else

$value="";

$row[$col."progressid_value"]=$value;



I must be a bit slow

T
thesofa 11/18/2006

I think he means this

Then add a coloring code just after. I.e.



shiould read as

"Then add a coloring code just after, for example"
Also your line of code thus

if($data["progressid"]="1")



should this not have 2 equal signs, like this?

if($data["progressid"]=="1")



I am sure that if you are saying if the value in data["progressid"] is 1, then do summat

what you have done is set the variable to a value of 1.
On the other hand, I may be wrong, because some of the other examples only have one = sign.

I was convinced that using the comparison operator needs 2 = signs, and if you want to check that it is the same value and the same type of field, you uase three ===

You can read a lot more about it here PHP Operators

How starnge that a page about PHP operators is served from .asp pages?????
I hope this has helped sort the last few niggles for you.

Cheers M8

G
gdude66 11/18/2006

I think he means this

shiould read as

"Then add a coloring code just after, for example"
Also your line of code thus

if($data["progressid"]="1")



should this not have 2 equal signs, like this?
I am sure that if you are saying if the value in data["progressid"] is 1, then do summat

what you have done is set the variable to a value of 1.
On the other hand, I may be wrong, because some of the other examples only have one = sign.

I was convinced that using the comparison operator needs 2 = signs, and if you want to check that it is the same value and the same type of field, you uase three ===

You can read a lot more about it here PHP Operators

How starnge that a page about PHP operators is served from .asp pages?????
I hope this has helped sort the last few niggles for you.

Cheers M8



Cheers

That did it

Thanks G

T
thesofa 11/19/2006

HTH