This topic is locked

Change table cell color

6/1/2007 10:44:38 PM
PHPRunner General questions
S
spoilar author

I would like to change the background color of a table cell based on a field value that meets certain conditions.
The conditions are:
Red Background (must meet both conditions)ex. (RETDATE background would be red)

RETDATE dateship
05/22/2007


Yellow Background (must meet both conditions)ex. (RETDATE background would be yellow)

RETDATE dateship
05/23/2007


Green Background (must meet both conditions)ex. (RETDATE background would be green)

RETDATE dateship
05/28/2007 06/01/2007


This would all go into one (RETDATE) Custom "View as"

Is this possible?

Sergey Kornilov admin 6/4/2007

Set View as type of this field to Custom. Here is the sample code that does similar job. You need to modify it adding date diff calculation.

$str = "<table width=100% bgcolor=";

if ($value=="DONE")

$str.="green";

if ($value=="NOT STARTED")

$str.="red";

str.="><tr><td>".$value."</td></tr></table>";

$value=$str;
S
spoilar author 6/4/2007

This is what I have so far. Does this seem right. I am still trying to figure out how to do the rest.
How would I compare the value of two fields? And will the BETWEEN clause work here for the date range?
ex. 2. dateship field value is equal to or less than RETDATE field value -9 (RETDATE is a date field.)
I know how to do this (I think), but I am having a brain freeze right now. If someone would be kind enough to lead me in the right direction, I would be greatful!

$str = "<table width=100% bgcolor=";

if (($value==NULL) && ($value['dateship']>=now()-10))

$str.="red";

str.="><tr><td>".$value."</td></tr></table>";

$value=$str;
S
spoilar author 6/4/2007

Is this looking right? Or is it too much? I don't have access to my program right now (it's at work).

$str = "<table width=100% bgcolor=";

if (($value==NULL) && ($value['dateship']>=now()-10))

$str.="red";

if (($value==NULL) && ($value['dateship']<>now()) && ($value['dateship']>=now()-9))

$str.="yellow";

$str.="><tr><td>".$value."</td></tr></table>";

$value=$str;


Still trying to figure out how I am going to compare the difference in two date fields.
I would need the background to be green if the retdate and dateship fields were less than 10 days apart. If the return date was 10 days or less than the date shipped.
Something like
if ($value['dateship']<=$value-10)

$str.="green";

Sergey Kornilov admin 6/5/2007

To calculate the difference between two dates you can use DateDiff function.

This function is not built-in into PHP. Check this article for more info:

http://www.ilovejackdaniels.com/php/php-datediff-function

S
spoilar author 6/8/2007

I finally got this to work using this code snippet and the datediff.

$str = "<table width=100% bgcolor=";

if (($value==NULL) && ($data['warr']>10) || ($value<>NULL) && ($data['turnaround']>10)){

$str.="red";

}

elseif (($value==NULL) && ($data['dateship']<>now()) && ($data['warr']<=10)){

$str.="yellow";

}

$str.="><tr><td>".$value."</td></tr></table>";

$value=$str;


But the problem now, is that the field is a date field. I would like it to display as a short date (01/26/2007). Right now it is displaying 2007-01-26. How do I change this?

Alexey admin 6/8/2007

Hi,
try using this line in your code:

...

$str.="><tr><td>".format_shortdate(db2time($value))."</td></tr></table>";

...

S
spoilar author 6/8/2007

That worked perfectly! Thank you!

S
spoilar author 6/8/2007

Now I have a new problem.
When I export to excel I get this in the field.
<table width=100% bgcolor=><tr><td></td></tr></table>
I am using phprunner v3.1 build 218