我正在尝试将输出设置为“日期未确认”,如果日期来自MySQL = 2013-12-25& $ daydiff =“anything”并输出“Not available”如果MySQL date =“NULL”&和$ daydiff =“任何事情”
我的代码似乎不起作用,有什么建议或替代方案吗?
$ArrivalDate == $variants_data['ArrivalDate'];
$daydiff=floor((abs(strtotime(date("Y-m-d")) - strtotime($ArrivalDate))/(60*60*24)));
if ( $daydiff == '%wildcard%' && $ArrivalDate == '2013-12-25') {
$ETA ='Date Not Confirmed';
}
elseif ( $daydiff == '%wildcard%' && $ArrivalDate == 'NULL') {
$ETA ='Not available';
}
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';
}
else
{
$ETA ='';
}
答案 0 :(得分:0)
你在if子句中分配变量......单个“=”正在分配。我假设您要检查所以您需要“==”:)
if (!empty($daydiff) && $ArrivalDate == '2013-12-25') {
$ETA ='Date Not Confirmed';
}
elseif (is_null($ArrivalDate) || $ArrivalDate == 'NULL') {
$ETA ='Not available';
}
答案 1 :(得分:0)
你的输出是什么?始终“未确认日期”?
我猜是这样,因为“=”不比较字符串:
if ( $daydiff = '%wildcard%' && $ArrivalDate = '2013-12-25') {
$ETA ='Date Not Confirmed';
}
将是
if ( $daydiff == '%wildcard%' && $ArrivalDate == '2013-12-25') {
$ETA ='Date Not Confirmed';
}
但是,'%wildcard%'不是什么东西,PHP取而代之的是“任何东西”。那么,你的确切错误是什么?如果没关系,$ daydiff是什么,只是让它超出你的条件。