SQL零返回错误答案 [英] SQL Zero Returns Wrong Answer

查看:105
本文介绍了SQL零返回错误答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道答案是"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");

推荐答案

else if (numrows == 0)
else if (numrows == 0)


我认为您需要花更多的时间学习编程指南,而花更少的时间发布相同的基本问题一遍又一遍.
I think you need to spend more time studying your programming guides and less time posting the same basic question over and over again.


我在这里变得很认真deja vu:我们以前来过这里!

I am getting serious deja vu here: we have been here before!

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零返回错误答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆