$q=2013
$sql="SELECT * FROM vip_sales WHERE type = 'vecka' and date >= '"$q ."-01-01' and date <= '"$q ."-01-31' ";
$result = mysql_query($sql, $con);
$janw = mysql_num_rows($result);
$sql="SELECT * FROM vip_sales WHERE type = 'manad' and date >= '"$q ."-01-01' and date <= '"$q ."-01-31' ";
$result = mysql_query($sql, $con);
$janm = mysql_num_rows($result);
$sql="SELECT * FROM vip_sales WHERE type = 'ar' and date >= '"$q ."-01-01' and date <= '"$q ."-01-31' ";
此行'“$ q。” - 01-01'是=“2013-01-01”?
我用来构建代码的程序说有错误但我找不到任何错误我在PHPadmin中测试了这个
$sql="SELECT * FROM vip_sales WHERE type = 'ar' and date >= '2013-01-01' and date <= '2013-01-31' ";
它工作正常。我只是想确保这是正确的使用方法。 当我测试时,Cuse
$sql="SELECT * FROM vip_sales WHERE type = 'ar' and date >= '"2013 ."-01-01' and date <= '"2013 ."-01-31' ";
它正在工作。我可能会混淆'和'。
感谢您的帮助
答案 0 :(得分:2)
我想你需要另一个点。连接时,您应该在任何字符串和任何变量之间有一个句点。在这里阅读更多http://php.net/manual/en/language.operators.string.php
"SELECT * FROM vip_sales WHERE type = 'manad' and date >= '" . $q ."-01-01' and date <= '" . $q ."-01-31' ";
答案 1 :(得分:1)
试试这个
$sql="SELECT * FROM vip_sales WHERE type = 'vecka' and date >= '".$q."-01-01' and date <= '".$q."-01-31'";
它将为您提供以下SQL查询:
SELECT * FROM vip_sales WHERE type = 'vecka' and date >= '2013-01-01' and date <= '2013-01-31'