PHP表(日期)基于有效性的动态颜色更改 [英] PHP table (Date) dynamic color change based on validity
本文介绍了PHP表(日期)基于有效性的动态颜色更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<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>
下面是我的表格,它用于跟踪证书的有效性,从Lfour每年到Fouryearly的列是日期字段,我想根据有效性对这些字段进行有条件的颜色格式化...就像如果有效-绿色,已过期-红色的.
Below is my table, it is to track the validity of certificates, columns from Lfour yearly till Fouryearly are date fields, i would like to conditional color format these fields based on validity... Like If valid - Green, Expired - Red.
推荐答案
由于PHP> = 5.2.0,您可以这样使用DateTime类:
Since PHP >= 5.2.0 you can use the DateTime class as such:
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构造函数的字符串.
The string passed to the DateTime constructor is parsed according to these rules.
以下是您的代码示例:
<td class="exdate" style="color:<?php echo (new DateTime() > new DateTime($rows['Six_Monthly'])) ? 'red' : 'green'; ?>;" ><? echo $rows['Six_Monthly']; ?></td>
这篇关于PHP表(日期)基于有效性的动态颜色更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文