mysql - php show red, amber or green colour div depending on how many days left to go? -


this question has answer here:

i have php script tells user when document expire. want amend script , add traffic lighting it, mean if document due expire in 7 days or less show red colour div, otherwise if document due expire in 30 days or less show amber div, or if document not due expire prior 30 days show green colour div.

can please show me how can amend script need do, thanks.

php:

        <?php   include 'config.php';  $data = mysql_query("select timestampdiff(day, insurance_date, now()) expire_date    supplier_stats")   or die(mysql_error()); ?>                <?php  include 'config.php'; $result = mysql_query("select timestampdiff(day, insurance_date, now()) expire_date                           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&nbsp;|&nbsp;<font color=\"red\">";              $data = mysql_query("select * 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 make function maps days left color:

function traffic_light($days){   if($days <= 7) return 'red';   else if($days <= 30) return 'yellow';   else return 'green'; } 

and alter code displays lines use select color:

echo "<p>insurance expires in <font color=\"".traffic_light($days)."\">{$row['expire_date']} day(s)</font></p>"; 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -