php表(日期)动态颜色变化

nmpmafwu  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(300)
<div class="table-responsive">  
<table id="Well_CAT" class="table table-striped table-bordered">                              
<thead> <th>Client_Contract_Number</th>
<th>Currently_Using</th>
<th>MBPS_EAM_Number_RIGT</th>
<th>Model_and_Type</th>
<th>LFour_Yearly</th>
<th>Six_Monthly</th>
<th>One_Yearly</th>
<th>One_and_Half_Yearly</th>
<th>Two_Yearly</th>
<th>Two_and_Half_Yearly</th>
<th>Three_Yearly</th>
<th>Three_and_Half_Yearly</th>
<th>Four_Yearly</th>
<th>Remarks</th>
</thead>  
<?php
while($rows=mysql_fetch_array($result)){
?><tr>  
 <td class="exdate"><? echo $rows['Client_Contract_Number']; ?></td>
 <td class="exdate"><? echo $rows['Currently_Using']; ?></td>
 <td><? echo $rows['MBPS_EAM_Number_RIGT']; ?></td>
 <td><? echo $rows['Model_and_Type']; ?></td>
 <td><? echo $rows['LFour_Yearly']; ?></td>
 <td class="exdate"><? echo $rows['Six_Monthly']; ?></td>
 <td class="exdate"><? echo $rows['One_Yearly']; ?></td>
 <td class="exdate"><? echo $rows['One_and_Half_Yearly']; ?></td>
 <td class="exdate"><? echo $rows['Two_Yearly']; ?></td>
 <td class="exdate"><? echo $rows['Two_and_Half_Yearly']; ?></td>
 <td class="exdate"><? echo $rows['Three_Yearly']; ?></td>
 <td class="exdate"><? echo $rows['Three_and_Half_Yearly']; ?></td>
 <td class="exdate"><? echo $rows['Four_Yearly']; ?></td>
 <td class="exdate"><? echo $rows['Remarks']; ?></td>
  </tr>  
    <?php
     }
     ?>
  </table>

下面是我的表格,它是为了跟踪证书的有效性,从四年一次到四年一次的列是日期字段,我想根据有效性设置这些字段的条件颜色格式。。。比如有效期-绿色,过期-红色。

aiazj4mn

aiazj4mn1#

由于php>=5.2.0,因此可以使用datetime类:

if (new DateTime() > new DateTime("2010-05-15 16:00:00")) {
    # current time is greater than 2010-05-15 16:00:00
    # in other words, 2010-05-15 16:00:00 has passed
}

传递给datetime构造函数的字符串将根据这些规则进行解析。
下面是一个代码示例:

<td class="exdate" style="color:<?php echo (new DateTime() > new DateTime($rows['Six_Monthly'])) ? 'red' : 'green'; ?>;" ><? echo $rows['Six_Monthly']; ?></td>

相关问题