PHP - 将日期与当前日期进行比较
我在数据库中有以下内容
I have following in the database
$checktime = mysql_query("SELECT * FROM drafts WHERE page='sched'");
while($row = mysql_fetch_array($check)){
if($row['posted'] = date('j-n-Y'))
{
echo "ok";
}
}
我想将此日期与今天的日期进行比较。如果大家都知道,请帮助我。
I'd like to compare this date against today's date. Please help me if everyone knows. thank you!
条件错误,应该有两个等于符号 ==
Condition is wrong, it should have two equals to signs ==
if($row['posted'] == date('j-n-Y'))
请注意,一个等于符号是指派,这意味着
Please Note that one equal to sign is for assignment, it means that
$row['posted'] = date('j-n-Y')
上面的代码将 date('jn-Y')
的值赋给 $ row [ '
The above code will assign the value of date('j-n-Y')
into $row['posted']
您的作业不会执行任何操作,只需返回 true
每次它会进入if条件块
And your assignment will do nothing but just return true
, so every time it will go into the if condition block
其中两个等于符号 ==
用于压缩。所以在你的条件double等于,代码将只进入if条件块当你的 $ row ['posted']
等于 date('jn-Y')
where as the two equals to signs ==
are use for compression. so in your condition with double equals to, the code will only go into the if condition block when your $row['posted']
is equal to date('j-n-Y')
注意: mysql _ *
函数正式被弃用(从PHP 5.5开始,它很可能在下一个主要版本中被删除。)
NOTE: mysql_*
functions are Officially deprecated (as of PHP 5.5. It's likely to be removed in the next major release.)
你需要看看这个为什么我不应该在PHP中使用mysql_ *函数?