更改颜色取决于日期值

Change colors depends of values of the date

我想根据日期的持续时间更改整行的颜色。 例如,如果日期持续时间在 3 到 6 之间,颜色为橙色;超过 6 个必须显示为红色。我可以知道我该怎么做吗?

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

以上代码在php我如何计算周期时间选项卡中。对于dt_issue,它在插入查询时使用with now()。我将在下面插入屏幕截图。

你可以试试这个来改变字体的颜色取决于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>";

如果你想改变整行的颜色,你应该在回显 <tr> 标签之前做,比如 echo "<tr style=\"color:$color\">";

整行示例:

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