one more quick question, retrieving numbers from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

one more quick question, retrieving numbers from database

Post 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
}
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: one more quick question, retrieving numbers from database

Post 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 !==
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: one more quick question, retrieving numbers from database

Post 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.
Post Reply