Change color depending on date value
P粉459440991
P粉459440991 2024-04-03 13:11:25
0
1
377

I want to change the color of the entire row based on the duration of the date. For example, if the date's duration is between 3 and 6, the color is orange; more than 6 must be displayed in red. May I know how I can do this?

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>";
  
}

The above code is how I calculate cycle time tab in php. For dt_issue, this is used with now() when inserting the query. I'll insert a screenshot below.

P粉459440991
P粉459440991

reply all(1)
P粉947296325

You can try changing the font color based on daysdiff

echo "\n";
$now = time();
$your_date = strtotime($v["dt_issue"]);
$datediff = $now - $your_date;
$daysDiff = round($datediff / (60 * 60 * 24));
$color = $daysDiff \n";
echo  "&nbsp " .$daysDiff." &nbsp &nbsp ";
echo  "\n";
echo  "";
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!