douchun1948 2014-04-15 09:48
浏览 29

如果日期在7天内,php显示红色div,否则显示其他颜色div?

I have a script that tells the user when something is about to expire in the database, so for instance if something expires on the 20th april, and today is the 15th, then it will tell the user there are 5 days left until it expires.

Now i want to add to my script to say if there are 7 days or less till expire date, then show a red coloured div, else if there are less than 30 days but more than 7, show a yellow coloured div, and otherwise if there are more than 30 days left till something expires, show a green coloured div.

can someone please show me what i could do, thanks

<?php 
    include 'config.php';
    $data = mysql_query("SELECT TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date
                            FROM supplier_stats") or die(mysql_error());
?>

<?php 
    include 'config.php';
    $result = mysql_query("SELECT TIMESTAMPDIFF(DAY, insurance_date, NOW()) AS expire_date 
                             FROM supplier_stats") or die(mysql_error()); 
    while($row = mysql_fetch_array($result)) 
    {
        $days = $row['expire_date'] -1;
        if ($days > 0)
        {
            echo "<p>Insurance expires in <font color=\"red\">{$row['expire_date']} day(s)!</font></p>"; 
        }
        else
        {
            $when = $days*-1;           
            echo "<p>Insurance expires";
            if ($when > 1){
                echo " in {$when} days</p>";
            }
            elseif ($when ===1)
            {
                echo " tomorrow</p>";
            }
            elseif ($when > 0)
            {
                echo " today</p>";
            }
        }
    } 
?>
  • 写回答

1条回答 默认 最新

  • dqu92800 2014-04-15 09:52
    关注

    Something like:

    <?
      if ($when <= 7) $color = "red";
      else if ($when <= 30) $color = "yellow";
      else $color = "green";
      echo "<div style='background-color: {$color};'>Expires in {$when} day(s)</div>";
    ?>
    

    Obviously, you would need to adjust this to fit your code.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度