PHP MySQL 日期比较 [英] PHP MySQL Date Comparsion
本文介绍了PHP MySQL 日期比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含 Data1、data2、data3...Data7 行的 Mysql,我想与当前日期进行比较,搜索互联网我到目前为止得到了这个:
I Have a Mysql with the rows Data1,data2,data3...Data7 and i want to compare with the current date,searching the internet i got this so far:
$curDate = date("Y-m-d");
$query = "SELECT Id FROM Programacao where Data1 = $curDate";
$result = mysql_query($query);
if(!$result) {echo 'Nada';}
while ($row = mysql_fetch_array($result))
{
echo "Id = ".$row ['Id'];
}
但是我只能读取第一个,是否可以同时比较所有这些?
But i can read only the first one,does it possible to compare all of them at the same time?
推荐答案
您应该使用逻辑运算符.如果您需要检查 Data
中的至少一个是 $curDate
You should use logic operators. If you need check that AT LEAST ONE of Data
is $curDate
$query = "
SELECT Id
FROM Programacao
WHERE Data1 = $curDate
OR Data2 = $curDate
OR Data3 = $otherDateIfYouNeedOther
";
如果您需要检查所有这些都没有问题,您应该将 or
替换为 and
.
You should replace or
by and
if you need to check that ALL OF THEM are OK.
此外,据我所知你应该在引号中使用日期值,所以正确的是
Besides, As far as I remember You should use Date values in quotes, so correct one is
$query = "
SELECT Id
FROM Programacao
WHERE Data1 = '$curDate'
OR Data2 = '$curDate'
OR Data3 = '$otherDateIfYouNeedOtherOrSameOtherwise'
";
这篇关于PHP MySQL 日期比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文