我需要一张表,将日期分为:

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


我似乎无法正确理解。这是我的选择语句,返回结果:

$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>

07-28 01:10
查看更多