praefect Posted January 18, 2007 Share Posted January 18, 2007 Goodday all,Perhaps you can help shed some light on this: [code] $query = "select count(clientid) as c from xxx where clientid='".$this->session->getclientid()."'"; $cnt = $this->db->selectSQL($query); $valid = $valid and $cnt['c']<=GSInfo::$maxGS; [/code]Now, the value of $cnt at this point is 22, and the value of GSInfo::$maxGS is 15. For whatever reason, php is setting $valid to true, when clearly 22<=15 is false. I thought perhaps that the sql query might be spitting out a string, but this would not be an issue in PHP correct? Perhaps its a lack of understanding on my part on the behaviour of PHP vs C++/Java/Ada. Thanks for the help,Rob Quote Link to comment https://forums.phpfreaks.com/topic/34769-issue-with-operator-and-integer-values/ Share on other sites More sharing options...
redbullmarky Posted January 18, 2007 Share Posted January 18, 2007 i havent checked this out, but depends on the order of operators - ie, which gets dealt with first when calculating:[code]$valid = $valid and $cnt['c']<=GSInfo::$maxGS;[/code]it seems that, given the numbers you state, the above is being evaluated as ($valid and $cnt['c']) <= GSInfo::$maxGS; . try throwing in some brackets to specifically state your order:[code]$valid = $valid && ($cnt['c'] <= GSInfo::$maxGS);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34769-issue-with-operator-and-integer-values/#findComment-163896 Share on other sites More sharing options...
praefect Posted January 18, 2007 Author Share Posted January 18, 2007 Thanks redbullmarky. It was more my use of "and" instead of "&&" which appears to be the problem vs the actual (). Rob Quote Link to comment https://forums.phpfreaks.com/topic/34769-issue-with-operator-and-integer-values/#findComment-163901 Share on other sites More sharing options...
redbullmarky Posted January 18, 2007 Share Posted January 18, 2007 cool!even still.i actually find it always pays anyway to use brackets - both from a debugging point of view, but also a portability one. There's countless occasions I can think of where I've been required to go through code written using one language putting brackets in for another language, due to the calculation order being different.anyway - glad it helped!cheers Quote Link to comment https://forums.phpfreaks.com/topic/34769-issue-with-operator-and-integer-values/#findComment-163910 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.