0

如果 MySQL 的日期 = 2013-12-25 & $daydiff = 'any',我正在尝试将我的输出设置为“<em>日期未确认”,如果 MySQL 日期 =“,则输出“<em>不可用” NULL” & 和 $daydiff = '任何'

我的代码

$ArrivalDate = $variants_data['ArrivalDate'];

$daydiff=floor((abs(strtotime(date("Y-m-d")) - strtotime($ArrivalDate))/(60*60*24)));

if ( $daydiff = ''  AND $ArrivalDate ='2013-12-25') {
    $ETA ='Date Not Confirmed';
}

elseif ( $daydiff = ''  AND $ArrivalDate ='NULL') {
    $ETA ='Not available';
}

elseif ( $daydiff < '0') {
    $ETA ='';
}
elseif ( $daydiff < '31' ) {
    $ETA ='Within 30 days';
}

elseif ( $daydiff > '31' ) {
    $ETA ='1 Month';
}

elseif ( $daydiff < '60' )  {
    $ETA ='2 Months';
}

elseif ( $daydiff < '90' ) {
    $ETA ='3 Months';
}

elseif ( $daydiff < '121' ) {
    $ETA ='4 Months';
}

elseif ( $daydiff < '152' ) {
    $ETA ='5 Months';
}

elseif ( $daydiff < '182' ) {
    $ETA ='6 Months';
}

elseif ( $daydiff < '213' ) {
    $ETA ='7 Months';
}

elseif ( $daydiff < '245' ) {
    $ETA ='8 Months';
}

elseif ( $daydiff < '274' ) {
    $ETA ='9 Months';
}

elseif ( $daydiff < '304' ) {
    $ETA ='10 Months';
}

elseif ( $daydiff < '334' ) {
    $ETA ='11 Months';
}

elseif ( $daydiff < '365' ) {
    $ETA ='12 Months';
}

else
{
$ETA ='Not Applicable';
}

到目前为止,代码没有给我所需的结果,我什么时候出错了?

4

2 回答 2

2

重读后,我注意到您使用赋值运算符 ( =) 进行初始比较。您应该改用相等运算符 ( ==)。你的前几个条件应该是:

if ( $daydiff == '' && $ArrivalDate == '2013-12-25') {
    $ETA ='Date Not Confirmed';
} elseif ( $daydiff == '' && $ArrivalDate == 'NULL') {
    $ETA ='Not available';
}

此外,可以$ArrivalDate设置为字符串值,"NULL"还是您的意思NULL是什么都没有?

于 2013-04-08T15:08:10.640 回答
0

您可能通常会在 1 个月或更长时间内获得 1 个月的 ETA?尝试向您的 elseif 语句添加多个条件,因为您的第一个 elseif 语句将在 31 天后始终为真。所以像..

elseif ( $daydiff > 30 && $daydiff < 60 ) { // anything between 31 and 59 days is 1 month
$ETA ='1 Month';
}

elseif ( $daydiff > 60 && $daydiff < 90  )  { // anything between 61 and 89 days is 2 months
$ETA ='2 Months';
}

等等...

于 2013-04-08T14:43:41.237 回答