-1
$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' ";

它没有工作。我可能混淆了'和'。

感谢所有帮助

4

2 回答 2

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' ";
于 2013-10-08T21:02:07.243 回答
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'
于 2013-10-08T21:02:25.600 回答