This topic is locked
[SOLVED]

  Change color of Data if expired

7/19/2011 11:35:48 AM
PHPRunner General questions
S
sickacid author

Hi, in editor -> view as -> custom
i've put this code, if days difference from now to DataDocumento Field is >2 the color must be red else green but i get error type 8, Undefined variable value. Can somebody help me please? thanx a lot! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=17404&image=1&table=forumtopics' class='bbc_emoticon' alt=':D' />
$diff = abs(strtotime("now") - strtotime($values["DataDocumento"]));

$years = floor($diff / (365606024));

$months = floor(($diff - $years
365606024) / (30606024));

$days = floor(($diff - $years 365606024 - $months30606024)/ (606024));
if ($days<2)

$color="green";

else

$color="red";

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

C
cgphp 7/19/2011

Try this:

$diff = abs(strtotime(now()) - strtotime($data["DataDocumento"]));

$years = floor($diff / (365*60*60*24));

$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));

$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
if ($days<2)

$color="green";

else

$color="red";

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


now is a function not a string, so

"now"



becomes

now()


If you want to access fields values inside "view as custom", you have to use the data array, so

$values["DataDocumento"]



becomes

$data["DataDocumento"]


When you append vars inside a string remember the string concatenation operator '.'



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



becomes

$value="<font color='".$color."'>".$value."</font>";
S
sickacid author 7/19/2011

thank you very much for your teaching! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=59560&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />