我写了以下查询
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";
我不知道为什么会破坏,有什么想法?
答案 0 :(得分:4)
您将查询存储在$queryB
中,但使用$queryA
答案 1 :(得分: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";
答案 2 :(得分:0)
userID是否有默认值?如果默认值为NULL,则将查询更改为
$queryB = "SELECT COUNT(userID) From statistics WHERE userID IS NULL";
答案 3 :(得分:0)
不确定它是否会起作用......它只是首先想到的是: 当你使用转义双引号时怎么样?
$ queryB =“SELECT COUNT(userID)来自统计数据WHERE userID = \”\“”
答案 4 :(得分: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";