0

我写了以下查询

SELECT COUNT(userID) From statistics WHERE userID = ""

此查询显示未经验证的网站访问次数。

当我使用双引号时,该查询在 phpmyadmin 中有效,但是当我使用如下所示的单引号时它不起作用,它只是给了我存储在表中的记录数

 $queryB = "SELECT COUNT(userID) From statistics WHERE userID = ''";
 $resultB =mysql_query($queryA, $con) or die(mysql_error());
 $authB = mysql_result($resultB, "COUNT(userID)");

 echo "the number of authenticated visits were $authB<br />\n";

我不知道它为什么会坏,有什么想法吗?

4

5 回答 5

4

你存储你的查询,$queryB但你使用$queryA

于 2012-04-11T14:01:28.970 回答
0

不确定它是否会起作用......它只是首先想到的是:当你使用转义双引号时怎么样?

$queryB = "SELECT COUNT(userID) From statistics WHERE userID = \"\""

于 2012-04-11T14:03:18.917 回答
0

您应该对您的代码进行一些更改

$queryB = "SELECT COUNT(userID) From statistics WHERE userID = ''";
$resultB =mysql_query($queryB, $con) or die(mysql_error());
$authB = mysql_result($resultB, 0, 0);

echo "the number of authenticated visits were $authB<br />\n";
于 2012-04-11T14:03:46.000 回答
0

尝试这个:

 $queryB = "SELECT COUNT(userID) AS total From statistics WHERE userID = ''";
 $resultB =mysql_query($queryB, $con) or die(mysql_error());
$authB = mysql_fetch_assoc($resultB);
 echo "the number of authenticated visits were ".$authB['total']."<br />\n";
于 2012-04-11T14:01:57.607 回答
0

userID 有默认值吗?如果默认值为 NULL,则将查询更改为

$queryB = "SELECT COUNT(userID) From statistics WHERE userID IS NULL"; 
于 2012-04-11T14:02:10.533 回答