改变颜色取决于日期的值
P粉459440991
P粉459440991 2024-04-03 13:11:25
[PHP讨论组]

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

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

 $color= xxx;
 echo "";
 echo  "\n";
  echo "\n";
  echo  "\n";
  echo  "  " .$v["seal_area"]. "     ";
  echo  "\n";
  echo  "\n";

  echo "\n";
  echo  "\n";
  echo  "  " .$v["seal_barcode"]. "     ";
  echo  "\n";
  echo  "\n";
  
  echo "\n";
  echo  "\n";
  echo  "  " .$v["dt_issue"]. "     ";
  echo  "\n";
  echo  "";  
  
  echo "\n";
  echo  "\n";
  echo  "  " .$v["issue_admin"]. "     ";
  echo  "\n";
  echo  "";
  
  echo "\n";
  echo  "\n";
  echo  "  " .$v["receive_by"]."     ";
  echo  "\n";
  echo  "";

  echo "\n";
  echo  "\n";
  echo  "  " .$v["receive_id"]."     ";
  echo  "\n";
  echo  "";
 
  
  echo "\n";
  echo  "\n";
  echo  "  " .$v["dt_return"]."     ";
  echo  "\n";
  echo  "";

  echo "\n";
  echo  "\n";
  echo  "  " .$v["return_admin"]."     ";
  echo  "\n";
  echo  "";

  echo "\n";
  echo  "\n";
  echo  "  " .$v["return_by"]. "     ";
  echo  "\n";
  echo  "";
  
  echo "\n";
  echo  "\n";
  echo  "  " .$v["return_id"]."     ";
  echo  "\n";
  echo  "";
  
  /*echo "\n";
  echo  "\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  "  " .round($datediff / (60 * 60 * 24))."     ";
  echo  "\n";
  echo  "";*/
  
  echo "\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  "\n";
    echo  "  " .$daysDiff."     ";
    echo  "\n";
    echo  "";

  echo  "";
  
}

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

P粉459440991
P粉459440991

全部回复(1)
P粉947296325

您可以尝试根据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  "";
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号