开发者

PHP MySQL Date Comparsion

I Have a Mysql with the rows Dat开发者_StackOverflow中文版a1,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?


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
";

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'
";


SELECT Id,CASE 
    WHEN  Data1 = CURDATE() then 'Data1'
    WHEN  Data2 = CURDATE() then 'Data2'
    WHEN  Data3 = CURDATE() then 'Data3'
    ELSE ''
END as Data_Table
FROM Programacao
WHERE Data1 = CURDATE()
   OR Data2 = CURDATE()
   OR Data3 = CURDATE()
....
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜