我需要一个将日期分成的表格:
1. If the date is within the next 30 days - Red
2. If the date is over 30 days but under 60 - Orange
3. If the date is over 60 days - Green
我似乎无法正确理解这一点。这是我返回结果的 select 语句:
$result = mysqli_query($con,"SELECT a.ID, a.TITLE, b.VALUE_ID,
b.UF_CRM_1410772281, b.UF_CRM_1410772330 FROM b_crm_company a
INNER JOIN b_uts_crm_company b ON a.ID = b.VALUE_ID
WHERE UF_CRM_1410772281 = 1 GROUP BY a.TITLE ORDER BY UF_CRM_1410772330 ASC");
这是在表格中显示结果的 while 循环。您将看到我尝试分隔上面指定的结果之间的日期(请注意该表在 select 语句之前开始):
<table width="475">
<tr><th width="275"><b>Company</b></th><th width="200"><b>Renewal Date</b></th></tr>
while($row = mysqli_fetch_array($result))
{
$companyName = $row['TITLE'];
$supportRenewal = date('d/m/Y',strtotime($row['UF_CRM_1410772330']));
$id = $row['ID'];
if(strtotime($row['UF_CRM_1410772330']) < strtotime('+30 day')) {
print "<tr><td><strong style='color:#ff0000;'>$companyName</strong></td><td>
<strong style='color:#ff0000;'>$supportRenewal</span></td></tr>";
}
if ((strtotime($rows['UF_CRM_1410772330']) > strtotime('+30 day'))
and (strtotime($rows['UF_CRM_1410772330']) < strtotime('+60 day'))) {
print "<tr><td><strong style='color:#ff8400;'>$companyName</strong></td>
<td><strong style='color:#ff8400;'>$supportRenewal</span></td></tr>";
}
if(strtotime($row['UF_CRM_1410772330']) > strtotime('+90 day')) {
print "<tr><td><strong style='color:#ff0000;'>$companyName</strong></td><td>
<strong style='color:#ff0000;'>$supportRenewal</span></td></tr>";
}
}
?>
</table>
当我想的时候,这似乎不起作用,有人可以指出我哪里出错了
最佳答案
你应该这样做
<?php
$array = array('2014-11-15','2014-12-08','2015-01-10','2015-7-05');
foreach($array as $date) {
$now = strtotime(date('Y-m-d'));
$newDate = strtotime($date);
if($newDate > $now) {
$dateDiff = ($newDate - $now)/(24*60*60);
echo $dateDiff;
if($dateDiff > 1 && $dateDiff <= 30) {
echo "Red =======<br>";
} else if($dateDiff > 30 && $dateDiff < 60) {
echo "Orange =======<br>";
} else {
echo "Green =======<br>";
}
}
}
?>
在您的代码中实现这一点。
<table width="475">
<tr><th width="275"><b>Company</b></th><th width="200"><b>Renewal Date</b></th></tr>
while($row = mysqli_fetch_array($result))
{
$companyName = $row['TITLE'];
$id = $row['ID'];
$now = strtotime(date('Y-m-d'));
$supportRenewal = strtotime($row['UF_CRM_1410772330']);
$dateDiff = ($supportRenewal - $now)/(24*60*60);
if($dateDiff <= 30) {
print "<tr><td><strong style='color:#ff0000;'>$companyName</strong></td><td>
<strong style='color:#ff0000;'>date('Y-m-d',$supportRenewal)</span></td></tr>";
}
if($dateDiff > 30 && $dateDiff < 60) {
print "<tr><td><strong style='color:#ff8400;'>$companyName</strong></td>
<td><strong style='color:#ff8400;'>date('Y-m-d',$supportRenewal)</span></td></tr>";
}
if($dateDiff > 60) {
print "<tr><td><strong style='color:#ff0000;'>$companyName</strong></td><td>
<strong style='color:#ff0000;'>date('Y-m-d',$supportRenewal)</span></td></tr>";
}
}
?>
</table>
关于php - 分离多个不同日期范围内的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26799235/