Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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");
Posted

else if (numrows == 0)
 
Share this answer
 
Comments
OriginalGriff 12-May-11 14:47pm    
At first glance I thought you were being facetious, then I noticed what you meant. Good point! It doesn't solve his problem, and it's one reason why I always set "Treat warnings as errors" but it is a very good point. Gets my 5, but it would have been worth your commenting on why that is important!
Albert Holguin 12-May-11 14:53pm    
good catch...
Kim Togo 13-May-11 3:54am    
Good catch. "numrows" will be assigned the value of "0".
C++ will you allow this. Where C# compiler will hit you with:

"Cannot implicitly convert type 'int' to 'bool'"
I think you need to spend more time studying your programming guides and less time posting the same basic question over and over again.
 
Share this answer
 
Comments
Kode King 12-May-11 16:21pm    
Perhaps you should spend "No Time" posting opinions on another persons abilities and instead post some "answers". That's the reason this forum is here. Not to tell people to read the manual!
Albert Holguin 12-May-11 16:45pm    
i agree... at least this guy is trying, i post mean stuff for people who don't try.
Richard MacCutchan 13-May-11 3:47am    
Yes, he's very trying! He has posted basically the same question at least three times now and been given lots of help. And now a simple expression error and he's straight back with another post, rather than using his brain and debugger to find a very basic error.
Albert Holguin 13-May-11 10:09am    
well, like others have suggested, you don't HAVE to read his posts or answer, if you chose to do so... your wasting your own time.
Richard MacCutchan 13-May-11 11:01am    
Well it obviously bothers you that I'm trying to help him. Maybe you could try to do the same rather than sniping at me.
I am getting serious deja vu here: we have been here before!

SELECT COUNT(*) FROM...
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)
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]
 
Share this answer
 
v3
Comments
Marc A. Brown 12-May-11 14:40pm    
Exactly. Well answered.
Albert Holguin 12-May-11 14:54pm    
good answer... and yes, does look familiar...lol
Member 7766180 12-May-11 15:01pm    
I've run test and the answer will either be "1" or "0". I've gotten both results. I simply want to add another if statemnet to this, If the result is "1" then "Access Permited" else if it's "0" then "No Access"
Member 7766180 12-May-11 15:28pm    
So what in this code is actually returning the "0"? Is it the row = mysql_fetch_row(res_set);
printf("Access Permited: %s\n",row[i]);

If so can I do...
If row[i] = 1 then
printf("Access")
else
printf("No Access")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900