我正在尝试在日期选择器中显示用户选择的2个日期之间的某些数据,但我没有找到正确编写查询的方法。总是出现此错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BETWEEN2013-04-14AND2013-04-15GROUP BY created_at ORDER BY created_at' at line 1
这是我到目前为止写的:
$sd=$_POST['sd'];
$ed=$_POST['ed'];
$query = mysql_query("SELECT count(name) As Subscribers,CAST(`created_at` AS DATE) As Date FROM gcm_users WHERE created_at BETWEEN".$_POST['sd']."AND".$_POST['ed']."GROUP BY created_at ORDER BY created_at")or die(mysql_error());
答案 0 :(得分:3)
添加空格:
$query = mysql_query("SELECT count(name) As Subscribers,CAST(`created_at` AS DATE) As Date FROM gcm_users WHERE created_at BETWEEN '".$_POST['sd']."' AND '".$_POST['ed']."' GROUP BY created_at ORDER BY created_at")or die(mysql_error());