views:

71

answers:

1

First of all, I am using the DATE_ADD function for MySQL. When trying to use $sqlA in php, it saids syntax error for some reason (mainly the area after WHERE). Why?

$sqlA = "SELECT $column_name FROM $table_name WHERE Date >= DATE_ADD(CURDATE(), - INTERVAL 3 DAY)";

However, it works without DATE_ADD:

$sqlB = "SELECT column FROM table WHERE Date >=  CURDATE() - INTERVAL 3 DAY ";

Notice I put the column name and table name in $sqlB? Well, I tried substituting it now with PHP and this fails. It says syntax error, why?

$sqlC = "SELECT $column_name FROM $table_name WHERE Date >=  CURDATE()-INTERVAL 3 DAY";
+2  A: 

You can't have the minus sign in front of INTERVAL. Use DATE_SUB instead.

Keith Randall