Page 1 of 1

one more quick question, retrieving numbers from database

Posted: Thu Jan 21, 2010 8:25 pm
by scarface222
Hey guys one more question for a while lol, I have been trying to get an if statement to return false by the following criteria and it does not seem to work, however it works if the variable $status=='any-alpha-character-word'.

I checked the data query and $status echoes as 1, just like I expect it to,

yet when I test it in the if statement it returns true, and the if statement executes the code within. Does php have a different way for comparing numbers? I tried changing the mysql data field to INT and VARCHAR with no luck.

Code: Select all

$check="SELECT * FROM table WHERE stat='$session->username''";
    $query=mysql_query($check);
    while ($row = mysql_fetch_assoc($query)) {
$status=$row['status'];
    }
 
if ($status!=="1"){
//Do something
}

Re: one more quick question, retrieving numbers from database

Posted: Thu Jan 21, 2010 10:59 pm
by AbraCadaver
Even though I would expect mysql to return a string regardless of the field type, it might be worthwhile to try != instead of !==

Re: one more quick question, retrieving numbers from database

Posted: Thu Jan 21, 2010 11:29 pm
by scarface222
I figured out the problem, which now I feel really dumb about there were two variables with the same name interfering with one of my queries. I didn't see it for a while so I assumed maybe there were a === to compare numbers but now I realize this is not so. = for defining and == for comparing anything. Thanks for your response though man as usual.