Home > Mobile >  Change colors depends of values of the date
Change colors depends of values of the date

Time:05-17

I want to change color of the whole line depends of duration of the date. Example, If duration of the date is between 3 and 6 color is orange; more than 6 must be show as red. May I know How can I make that?

foreach ($ary_list as $k => $v) {

 $color= xxx;
 echo "<tr style=\"color:$color\">";
 echo  "<tr bgcolor=\"#F5F5F5\">\n";
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["seal_area"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>\n";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["seal_barcode"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>\n";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["dt_issue"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";  
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["issue_admin"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["receive_by"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["receive_id"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
 
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["dt_return"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["return_admin"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["return_by"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  echo  "&nbsp " .$v["return_id"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  /*echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" color=\"#3C5F84\">\n";
  $now = time(); // or your date as well
    $your_date = strtotime($v["dt_issue"]);
    $datediff = $now - $your_date;

//echo round($datediff / (60 * 60 * 24));
    //echo $datediff->format('%R%a days');
  echo  "&nbsp " .round($datediff / (60 * 60 * 24))." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";*/
  
  echo "<td nowrap ".$rowspan.">\n";
    $now = time();
    $your_date = strtotime($v["dt_issue"]);
    $datediff = $now - $your_date;
    $daysDiff = round($datediff / (60 * 60 * 24));
    $color = $daysDiff < 3 ? '#3C5F84' : ($daysDiff <= 6 ? 'orange' : 'red');
    echo  "<font face=\"arial\" size=\"1\" color=\"$color\">\n";
    echo  "&nbsp " .$daysDiff." &nbsp &nbsp ";
    echo  "</font>\n";
    echo  "</td>";

  echo  "</tr>";
  
}

Above code is in php how I count for cycle time tab. For dt_issue, it use with now() while inserting to query. I will insert the screenshot below.

enter image description here

CodePudding user response:

You can try this to change the color of the font depends on daysdiff

echo "<td nowrap ".$rowspan.">\n";
$now = time();
$your_date = strtotime($v["dt_issue"]);
$datediff = $now - $your_date;
$daysDiff = round($datediff / (60 * 60 * 24));
$color = $daysDiff < 3 ? '#3C5F84' : ($daysDiff <= 6 ? 'orange' : 'red');
echo  "<font face=\"arial\" size=\"1\" color=\"$color\">\n";
echo  "&nbsp " .$daysDiff." &nbsp &nbsp ";
echo  "</font>\n";
echo  "</td>";

And if you want to change the color of the whole line , you should do it before echo the <tr> tag , like echo "<tr style=\"color:$color\">";

Whole line example:

foreach ($ary_list as $k => $v) {

  $now = time();
  $your_date = strtotime($v["dt_issue"]);
  $datediff = $now - $your_date;
  $daysDiff = round($datediff / (60 * 60 * 24));
  $color = $daysDiff < 3 ? '#3C5F84' : ($daysDiff <= 6 ? 'orange' : 'red');
  
 echo "<tr style=\"color:$color\" bgcolor=\"#F5F5F5\">";
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["seal_area"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>\n";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["seal_barcode"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>\n";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["dt_issue"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";  
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["issue_admin"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["receive_by"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["receive_id"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
 
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["dt_return"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["return_admin"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";

  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["return_by"]. " &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  echo  "&nbsp " .$v["return_id"]." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";
  
  /*echo "<td nowrap ".$rowspan.">\n";
  echo  "<font face=\"arial\" size=\"1\" >\n";
  $now = time(); // or your date as well
    $your_date = strtotime($v["dt_issue"]);
    $datediff = $now - $your_date;

//echo round($datediff / (60 * 60 * 24));
    //echo $datediff->format('%R%a days');
  echo  "&nbsp " .round($datediff / (60 * 60 * 24))." &nbsp &nbsp ";
  echo  "</font>\n";
  echo  "</td>";*/
  
  echo "<td nowrap ".$rowspan.">\n";
    echo  "<font face=\"arial\" size=\"1\" color=\"$color\">\n";
    echo  "&nbsp " .$daysDiff." &nbsp &nbsp ";
    echo  "</font>\n";
    echo  "</td>";

  echo  "</tr>";
  
}

  • Related