我有一个将数据插入数据库的表单。字段之一是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')

最佳答案

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

关于php - PHP mysql_query()手动输入日期有效,PHP变量不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16405331/

10-16 14:36