This topic is locked
[SOLVED]

 Change row background related to creating datetime

3/12/2017 1:57:40 PM
PHPRunner General questions
C
cardman3000 author

Hi together,
with this code in List page: After record processed event



if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:lightgreen;';


is possible to get two different colours: red background for datetime row older than 30 minutes and green for actually added and not older than 30 minutes. It works fine.
What do I need to get a third option: yellow for records which are between 15 amd 30 minutes old.

Red - older then 30 minutes

Yellow - between 15 and 30 minutes old

Green - 0 - 15 minutes old
Thanks in advance.

HJB 3/12/2017

Not tested, so, for inspiration purposes only ...

if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] >= date("Y-m-d H:i:s",strtotime("-15 minutes")))

$record["Order_date_css"]='background:yellow;';
if ($data["Order_date"] >= date("Y-m-d H:i:s",strtotime("-0 minutes")))

$record["Order_date_css"]='background:lightgreen;';
C
cardman3000 author 3/12/2017



Not tested, so, for inspiration purposes only ...
if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] >= date("Y-m-d H:i:s",strtotime("-15 minutes")))

$record["Order_date_css"]='background:yellow;';
if ($data["Order_date"] >= date("Y-m-d H:i:s",strtotime("-0 minutes")))

$record["Order_date_css"]='background:lightgreen;';


thanks walk2fly, I've already tested this way but it would not work.

There are an conflict with the time logic: all new created records becomes yellow background.
It must be solved differently. I have no idea at the moment. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81599&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />

HJB 3/12/2017

https://www.youtube.com/watch?v=Q3jx-x6zT14
... as off 2:20 minutes, a different coding appears

which you should give a try ..., HTH

lefty 3/12/2017

****>

https://www.youtube.com/watch?v=Q3jx-x6zT14
... as off 2:20 minutes, a different coding appears

which you should give a try ..., HTH


Won't work . We need help from admin here . I have tried all types of php date functions in after processed event and have not got this to work. ( tests using different fieldname on my audit log ).



Tried this : would not work
Red background
date_default_timezone_set('EST');

$start = Now();
if ($data["datetime"] >= date('Y-m-d H:i:s',strtotime('+30 minutes',strtotime($start))))

$record["datetime_css"]='background:red;';
elseif ($data["datetime"] < date('Y-m-d H:i:s',strtotime('+30 minutes',strtotime($start))))

$record["datetime_css"]='background:lightgreen;';


Tried This : would not work
Red Background
$value = now();
if (($data["datetime"]) >= strtotime($value, '- 30 minutes' )) {

$record["datetime_css"]='background:red;';
}
elseif (($data["datetime"]) < strtotime($value , '-30 minutes')) {

$record["datetime_css"]='background:lightgreen;';
} else {

}
Tried This : would not work RED Background
$t = now();
if (strtotime($data['datetime']) >= (date("d/m/Y h:i:s", strtotime("+30 minutes", $t)))) {

$record["datetime_css"]='background:red;';
}
if (strtotime($data['datetime']) < (date("d/m/Y h:i:s", strtotime("+30 minutes", $t)))) {

$record["datetimecss"]='background:lightgreen;';
} else {

}
This was my original from cardman3000 help message but kept - try but kept coming up green with my fields $data["datetime"] . Just won't work in after record processed event , which I have used many times to change font's , background etc.... Never DATES though._
Get Green background.with my test fields
if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:lightgreen;';


MYSQL Database - with datetime structure / PHPrunner with edit as date / view as datetime.
I know one of these are close.

HJB 3/13/2017



****
Won't work . We need help from admin here . I have tried all types of php date functions in after processed event and have not got this to work. ( tests using different fieldname on my audit log ).



Tried this : would not work
Red background
date_default_timezone_set('EST');

$start = Now();
if ($data["datetime"] >= date('Y-m-d H:i:s',strtotime('+30 minutes',strtotime($start))))

$record["datetime_css"]='background:red;';
elseif ($data["datetime"] < date('Y-m-d H:i:s',strtotime('+30 minutes',strtotime($start))))

$record["datetime_css"]='background:lightgreen;';


Tried This : would not work
Red Background
$value = now();
if (($data["datetime"]) >= strtotime($value, '- 30 minutes' )) {

$record["datetime_css"]='background:red;';
}
elseif (($data["datetime"]) < strtotime($value , '-30 minutes')) {

$record["datetime_css"]='background:lightgreen;';
} else {

}
Tried This : would not work RED Background
$t = now();
if (strtotime($data['datetime']) >= (date("d/m/Y h:i:s", strtotime("+30 minutes", $t)))) {

$record["datetime_css"]='background:red;';
}
if (strtotime($data['datetime']) < (date("d/m/Y h:i:s", strtotime("+30 minutes", $t)))) {

$record["datetimecss"]='background:lightgreen;';
} else {

}
This was my original from cardman3000 help message but kept - try but kept coming up green with my fields $data["datetime"] . Just won't work in after record processed event , which I have used many times to change font's , background etc.... Never DATES though._
Get Green background.with my test fields
if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:lightgreen;';


MYSQL Database - with datetime structure / PHPrunner with edit as date / view as datetime.
I know one of these are close.


@John - This is showing else method: http://stackoverflow.com/questions/31486897/conditional-formatting-html-table-in-php-with-time-stamp-comparison

H
Hertz2P 3/21/2017

I think you need to use 'else if' code here. Here's a working example from one of my applications for inspiration:



If ($value <3) {

$color="GREEN";

} else if ($value <4) {

$color="ORANGE";

} else {

$color="RED";

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


Hope it helps!

H
Hertz2P 3/21/2017

Actually, one of yours looked pretty close to me... try this (untested):



$value = now();
if (($data["datetime"]) < strtotime($value, '- 15 minutes' )) {

$record["datetime_css"]='background:green;';
}elseif (($data["datetime"]) < strtotime($value , '-30 minutes')) {

$record["datetime_css"]='background:yellow;';
} else {

$record["datetime_css"]='background:red;';

}


Or try this one based on your original code:



if ($data["Order_date"] < date("Y-m-d H:i:s",strtotime("-16 minutes"))) {

$record["Order_date_css"]='background:green;';
}elseif ($data["Order_date"] < date("Y-m-d H:i:s",strtotime("-31 minutes"))) {

$record["Order_date_css"]='background:yellow;';
} else {

$record["Order_date_css"]='background:red;';

}
C
cardman3000 author 3/23/2017



Actually, one of yours looked pretty close to me... try this (untested):



$value = now();
if (($data["datetime"]) < strtotime($value, '- 15 minutes' )) {

$record["datetime_css"]='background:green;';
}elseif (($data["datetime"]) < strtotime($value , '-30 minutes')) {

$record["datetime_css"]='background:yellow;';
} else {

$record["datetime_css"]='background:red;';

}


Or try this one based on your original code:



if ($data["Order_date"] < date("Y-m-d H:i:s",strtotime("-16 minutes"))) {

$record["Order_date_css"]='background:green;';
}elseif ($data["Order_date"] < date("Y-m-d H:i:s",strtotime("-31 minutes"))) {

$record["Order_date_css"]='background:yellow;';
} else {

$record["Order_date_css"]='background:red;';

}



Thank you Hertz2P,
with the first option all rows become green background and with second option are all rows yellow.

It seems that "elseif" and "else" apparently doesn't work in List page: After record processed.

H
Hertz2P 3/23/2017



Thank you Hertz2P,
with the first option all rows become green background and with second option are all rows yellow.

It seems that "elseif" and "else" apparently doesn't work in List page: After record processed.


My bad.. I modded this from some working code I have in a project Event Page: After Record Processed...
It should work for you..



if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes") && $data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-15 minutes"))))

$record["Order_date_css"]='background:yellow;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-15 minutes")))

$record["Order_date_css"]='background:lightgreen;';


Let me know how it works..

L
laonian 3/23/2017

Also put my 2 cents here. I have not tested my code though.



$diff=floor((strtotime("today")-strtotime($data['Order_date']))/60);
if ($diff>30)

$record["Order_date_css"]='background:red;';





if ($diff<=30 and $diff>=15 )

$record["Order_date_css"]='background:yellow;';



if ($diff<15)

$record["Order_date_css"]='background:green;';



C
cardman3000 author 3/23/2017

Thank you for assistance.
Here are the results
@Hertz2P: 0 - 15 min green OK, 15 - 30 min yellow OK, over 30 min red NOK. It remains in yellow.
@alshine: background only green at all time
It's really tricky because all minutes >30 are in the same time also >15 <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81769&image=1&table=forumreplies' class='bbc_emoticon' alt=':ph34r:' />

lefty 3/23/2017



Thank you for assistance.
Here are the results
@Hertz2P: 0 - 15 min green OK, 15 - 30 min yellow OK, over 30 min red NOK. It remains in yellow.
@alshine: background only green at all time
It's really tricky because all minutes >30 are in the same time also >15 <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81770&image=1&table=forumreplies' class='bbc_emoticon' alt=':ph34r:' />


None of these will work as when time moves and compares they will all change Except for this one
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes") && $data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-15 minutes"))))

$record["Order_date_css"]='background:yellow;';
Order_date has to be involved with the right side of all expressions.

C
cardman3000 author 3/23/2017

Thank you guys, but none of these approaches will change my background into 3 colors.
This is my code, and it works:



if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:green;';


My Order_date field is "datetime".
I've tested all this approaches and changed the sequences, but none supports three colors. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81771&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />

H
Hertz2P 3/23/2017



Thank you guys, but none of these approaches will change my background into 3 colors.
This is my code, and it works:



if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:green;';


My Order_date field is "datetime".
I've tested all this approaches and changed the sequences, but none supports three colors. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81772&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />


Trust me, it is definitely possible.. I think I had a parenthesis in the wrong place...
try this one:



if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes")) && $data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-15 minutes")))

$record["Order_date_css"]='background:yellow;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-15 minutes")))

$record["Order_date_css"]='background:lightgreen;';


I don't think it was picking up the first part of the middle line...

C
cardman3000 author 3/24/2017

That's it! It works perfectly and the background changes the color every 15 minutes

Thank you Hertz2P, this was the solution:



if ($data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-30 minutes")))

$record["Order_date_css"]='background:red;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-30 minutes")) && $data["Order_date"] <= date("Y-m-d H:i:s",strtotime("-15 minutes")))

$record["Order_date_css"]='background:yellow;';
if ($data["Order_date"] > date("Y-m-d H:i:s",strtotime("-15 minutes")))

$record["Order_date_css"]='background:lightgreen;';


<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81776&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />