PHP mysql_query()手动输入日期工作PHP变量没有

时间:2013-05-06 18:57:49

标签: php mysql variables

我有一个将数据插入数据库的表单。其中一个字段是weDate,其中填入了

$weDate=date('Y-m-d',strtotime('Friday'))

如果我使用以下内容:

$sql = mysql_query("SELECT ID as 'DB_ID', 
                         partnumber as 'Part_Number', 
                         pndesc as 'Part Number Description', 
                         name as 'Name', 
                         reason as 'Reason', 
                         comment as 'Comments', 
                         date as 'Date', 
                         time as 'Time', 
                         weDate as 'Weekend Date' 
                    FROM $table 
                    WHERE weDate = '2013-05-03'");

我得到了结果。

当我尝试:

$sql = mysql_query("SELECT ID as 'DB_ID', 
                         partnumber as 'Part_Number', 
                         pndesc as 'Part Number Description', 
                         name as 'Name', 
                         reason as 'Reason', 
                         comment as 'Comments', 
                         date as 'Date', 
                         time as 'Time', 
                         weDate as 'Weekend Date'
                    FROM $table 
                    WHERE weDate = '$weDate2'");

我一无所获。为什么呢?

PHP变量是:

$weDate2 = date('Y-m-d', strtotime('-1 weeks Friday')

1 个答案:

答案 0 :(得分:3)

strtotime("Friday")返回即将到来的星期五,即5月10日。这不是硬编码查询中的5月3日。