This question already has an answer here:
i have a php script that tells the user when a document is about to expire. I now want to amend this script and add traffic lighting to it, by this i mean if a document is due to expire in 7 days or less then show a red colour div, otherwise if a document is due to expire in 30 days or less then show a amber div, or if a document is not due to expire prior to 30 days then show a green colour div.
can someone please show me how i can amend my script to do what i need it to do, thanks.
php:
<?php
include 'config.php';
$data = mysql_query("SELECT TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date
FROM supplier_stats")
or die(mysql_error()); ?>
<?php
include 'config.php';
$result = mysql_query("SELECT TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date
FROM supplier_stats") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$days = $row['expire_date'];
if ($days > 0)
{
echo "<p>Insurance expires in <font color=\"red\">{$row['expire_date']} day(s)</font></p>";
}
else
{
$when = $days*-1;
echo "<p><font color=\"red\">Insurance expires";
if ($when > 1)
{
echo " {$when} days | <font color=\"red\">";
$data = mysql_query("SELECT * FROM supplier_stats")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
echo date('d/m/Y',strtotime($info['insurance_date'])); echo"</font></p>"; }
}
elseif ($when == 1)
{
echo " yesterday!</p>";
}
else
{
echo " today!</font></p>";
}
}
}
?>
If I was you I would make a function that maps days left to color:
And then alter the code that displays lines to use it to select the color: