salinah20 Posted January 2, 2008 Share Posted January 2, 2008 I've been googling the net, and searching here, and all the answers I find seem to confuse me more than I was to start with. I'm hoping some kind hearted soul here can put me on the right path. For those have been coding PHP for a while this is probably a really easy question... I have 2 variables (they're set from a mysql database and are working just fine) that I'm trying to do an if-then kinda thing on. Something like: If $subscriber is null and $ppl is not null then do this If $ppl is null and $subscriber is not null then do this other thing If $subscriber is null and $ppl is null then do nothing I know how to fill in the "then do this" blank....what I can't seem to figure out is how to compare for "Is Null" or "Is Not Null" and put that in and If-Then-Else kinda thing. Can anyone help me out here? Quote Link to comment https://forums.phpfreaks.com/topic/84129-solved-if-variable-is-null-question/ Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 Does is_null() help? ps: However, you really ought test for this within your query if possible. Quote Link to comment https://forums.phpfreaks.com/topic/84129-solved-if-variable-is-null-question/#findComment-428251 Share on other sites More sharing options...
salinah20 Posted January 2, 2008 Author Share Posted January 2, 2008 That's half of it! Thanks! That works for the null fields....but how do I get it for the "not null" field? I tried is_not_null(), but that didn't work... Quote Link to comment https://forums.phpfreaks.com/topic/84129-solved-if-variable-is-null-question/#findComment-428255 Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 <?php if (is_null($var)) { // $var is null. } else { // $var is not null. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84129-solved-if-variable-is-null-question/#findComment-428256 Share on other sites More sharing options...
aschk Posted January 2, 2008 Share Posted January 2, 2008 Just like you do normal not (!) statements... if ( ! is_null( <statement> ) ) { then do blah... } Quote Link to comment https://forums.phpfreaks.com/topic/84129-solved-if-variable-is-null-question/#findComment-428258 Share on other sites More sharing options...
salinah20 Posted January 2, 2008 Author Share Posted January 2, 2008 That did it....the !is_null() that is. I figured it was an easy question. Thanks SO much! Quote Link to comment https://forums.phpfreaks.com/topic/84129-solved-if-variable-is-null-question/#findComment-428270 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.