Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The reason this is not working is that MYSQL_ROW row and an integer of 1 or 0 are not of the same data type. How would i make them the same data type?

           mysql_query(conn,"SELECT COUNT(*) FROM tblURL WHERE IP = '192.168.1.399' AND Status = 'Active'");
   my_ulonglong i = 0;
   res_set = mysql_store_result(conn);
   my_ulonglong numrows = mysql_num_rows(res_set);

   {
   row = mysql_fetch_row(res_set);
   if (row[i] = 1) //////THIS IS THE ISSUE??????/////////
       printf("YES: %s\n",row[i]);
   else
       printf("NO: %s\n",row[i]);
   }

   mysql_free_result(res_set);
   mysql_close(conn);
   system("PAUSE");
   /*End Works*/
}
Posted
Updated 12-May-11 23:26pm
v2

Take a look at the documentation here[^], which explains the data types returned by MySQL functions. mysql_fetch_row() returns a database row not an integral value.
 
Share this answer
 
Comments
Albert Holguin 13-May-11 10:23am    
See, being productive with responses is not so bad... :) ...my 5
Richard MacCutchan 13-May-11 10:52am    
I am always productive; but sometimes (as in this case) brute force is needed.
Albert Holguin 13-May-11 11:22am    
I see frustration is reaching an all-time high... lol
Member 7766180 13-May-11 10:50am    
Right, But that return is always a "1" or a "0" in my case. That is all that it will ever be. A "1" or "0".
Richard MacCutchan 13-May-11 10:55am    
You still seem incapable or unwilling to make an effort to read properly what you have been told. Go to the documentation and read carefully what it states about the return type of this function. Then go and find out how you can interpret that data and its content. Simply repeating this nonsense about 0 and 1 is getting you nowhere.
first off...

in an if statement:
if(x = 1)  //<-- this sets x to 1, not compares
if(x == 1) //<-- this compares


second (assuming the rest of your code is kosher, i'm pretending it is)...

you have to look up what MYSQL_ROW is typedef'ed from, if its an int, then a comparator should work, but if you need to cast it, you need to do an explicit cast (usually if you have to do this you should know what you're doing as far as data types, could lead to crashes, bugs, or loss of data):

MYSQL_ROW row;
int x= (int) row; //<-- again this sets it equal to

//In a statement
if(x == row) //<--this compares, but if they're compatible types the compiler should be ok with it
if(x == (int)row) //<--comparator with explicit cast

I'd help you more with the SQL portion of it but its been years since I last did SQL.

*****Update:*****
int value; //<--single integer value
int row[10]; //<-- array of 10 integers

if(row == 1) //<-- comparing pointer of array to one (this will likely never be one)
if(row[2] == 1) //<-- comparing third element to one (array indexing starts at zero)
 
Share this answer
 
v3
Comments
Member 7766180 12-May-11 20:25pm    
Thank you so much Albert! Informative and Learnative (made that up) at the same time! I tried several of the suggestions and this one debugs...
if (int(row) == 1)
printf("PASS: %s\n",row[i]);
else
printf("FAIL: %s\n",row[i]);

However; if the answer is either '0' or '1' it always returns "FAIL", I'm going to search some more on the "==" that you gave me. Once again, thank you.
DS
Albert Holguin 12-May-11 20:29pm    
int should be in parentheses, not row, now.... if row[i] is actually working (as in giving you a value that makes sense), then that means row must be a pointer to an array, so if you look at just row (without the []), then the value is some memory address that will likely never be 1
Member 7766180 12-May-11 20:29pm    
This always returns "PASS" Somehow I'll split the difference!
if (int(row) >= 1)
printf("PASS: %s\n",row[i]);
else
printf("FAIL: %s\n",row[i]);
Albert Holguin 12-May-11 20:30pm    
see my reply above, row is probably a pointer, hence always greater than 1
Albert Holguin 12-May-11 20:37pm    
expanded on explanation a little in the solution itself...

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