问题描述
我知道答案是"0",但它返回此if语句的第一部分.它应该返回第二部分"No Access"
I know the answer is "0" but it returns the first part of this if statement. It should return the second part "No Access"
mysql_query(conn,"SELECT COUNT(*) FROM tblURL WHERE IP = ''192.168.1.199'' AND Status = ''Active''");
my_ulonglong i = 0;
res_set = mysql_store_result(conn);
my_ulonglong numrows = mysql_num_rows(res_set);
if (numrows >= 1)
{
row = mysql_fetch_row(res_set);
printf("Access Permited: %s\n",row[i]);
}
else if (numrows = 0)
{
row = mysql_fetch_row(res_set);
printf("No Access: %s\n",row[i]);
}
mysql_free_result(res_set);
mysql_close(conn);
system("PAUSE");
推荐答案
SELECT COUNT(*) FROM...
返回包含一行的数据集.总是.
该行只有一列.总是.
整个数据集中的单个单元格包含数据库中匹配行的数量.
可以是0、1或任何其他整数值.
因此,行数(即返回的行数的计数)将始终为1.总是.
因此,您的测试
Returns a dataset containing one row. Always.
That row, has one column. Always.
The single cell in the entire dataset contains the number of matching rows in the database.
This could be 0, 1, or any other integral value.
So numrows - being the count of the number of rows returned - will always be one. Always.
So your test
if (numrows >= 1)
将始终成功.总是.总是.总是.
[edit]添加了一个额外的始终",以保持良好的效果. :D [/edit]
[edit]只是为了戏剧,增加了一个额外的"Always" [/edit]
will always suceed. Always. Always. Always.
[edit]Added an extra "Always" for good measure. :D[/edit]
[edit]Just for drama, an extra "Always" added[/edit]
这篇关于SQL零返回错误答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!