SQL返回错误的结果 [英] SQL Returns Wrong Result
本文介绍了SQL返回错误的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此查询始终返回"1",不太确定出什么问题了吗?
谢谢
DS
This query always returns "1", Not quite sure whats wrong?
Thanks
DS
<pre lang="cs">if (mysql_real_connect(conn,"urlock.db.5513143.hostedresource.com","VendorCheck","Reader1234","urlock",0,NULL,0) !=0)
{
legal = mysql_query(conn, "SELECT COUNT(*) FROM tblURL WHERE IP = ''192.168.1.1''");
if( legal != 0 )
{
printf(mysql_error(conn)); return 99;
}
result = mysql_store_result(conn);
printf("Legal: %d\n", mysql_num_rows(result));
mysql_free_result(result);
mysql_close(conn);
推荐答案
如果我正确解释了代码,则将轮询结果集以获取行数它具有,而不是实际的返回值.行数将始终为1,因为count
查询始终返回一个结果.换句话说,您正在查看结果的数量,而不是结果本身.至少是这样:)
有问题的代码:
If I''m interpreting the code correctly, then you''re polling the resultset for the number of rows it has, not the actual returned value. The number of rows will always be 1, since acount
query always returns one result. In other words, you''re looking at the number of results, not the result itself. At least, that''s what it looks like :)
Code in question:
printf("Legal: %d\n", mysql_num_rows(result));
我想知道在此和您的 ^ ]在您理解之前?SELECT
命令不会返回给出查询答案的值,而是会返回一个告诉您找到多少数据库行的值.然后,您需要解释这些行的内容以获取所需的信息.
发布像 C ++这样的注释不能返回整数!哦,男孩.仅显示您与已发布的任何响应(可能还有C ++和SQL)的理解相距甚远.
I wonder how many times this has to be explained to you in this and your previous question[^] before you understand? TheSELECT
command does not return a value giving the answer to your query, it returns a value telling you how many database rows it found. You then need to interpret the contents of those rows for the information you are looking for.
Posting comments like C++ can''t return integers!???! Oh boy. merely shows how far away you are from understanding any of the responses that have been posted, and possibly both C++ and SQL.
也许您只有一条匹配的记录在您的数据库中?
Perhaps you only have one matching record in your database?
这篇关于SQL返回错误的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文