wtfsmd Posted March 23, 2009 Share Posted March 23, 2009 How would i get this to work? I don't get any syntax errors it just doesn't want to work. <?php if ( !empty($icq) || !is_null($icq) ) { echo "this"; } ?> Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted March 23, 2009 Share Posted March 23, 2009 Where do you define (or not) $icq ? Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted March 23, 2009 Author Share Posted March 23, 2009 What do you mean? I just want to know if it is not empty or is not null Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted March 23, 2009 Share Posted March 23, 2009 Is the variable used in a Form or might it be coming from a DB query? Where is it coming from if it is not null or not empty? is oit an array? Does it simply appear out of thin air? Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted March 23, 2009 Author Share Posted March 23, 2009 Sorry i read that wrong It comes out of my MySQl db <?php $query = "SELECT * FROM user WHERE id='$id'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); $icq = $row['icq']; if ( !empty($icq) || !is_null($icq) ) { echo "this"; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 23, 2009 Share Posted March 23, 2009 do you mean this statement. <?php $a['name']==" "; $a['name']=NULL; if(empty($a['name'])&& is_null($a['name'])){ echo hi; } ?> Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted March 23, 2009 Author Share Posted March 23, 2009 do you mean this statement. <?php $a['name']==" "; $a['name']=NULL; if(empty($a['name'])&& is_null($a['name'])){ echo hi; } ?> no not like that, it comes out of my database. I want to know this "if $icq is not empty OR is not null" which is what my statement says. Quote Link to comment Share on other sites More sharing options...
trq Posted March 23, 2009 Share Posted March 23, 2009 Your original code works as expected. Obviously $icq isn't what YOU think it is however. Quote Link to comment Share on other sites More sharing options...
trq Posted March 23, 2009 Share Posted March 23, 2009 On top of that, empty returns true when its argument is NULL, so theres really no need to check for both. Quote Link to comment Share on other sites More sharing options...
wtfsmd Posted March 23, 2009 Author Share Posted March 23, 2009 Your original code works as expected. Obviously $icq isn't what YOU think it is however. I removed the " || !is_null ($icq) " from the statement and it works as expected. When i look at the row in my DB its empty As for the new post i am dumb for not even realizing that empty returns true for null, and that works just fine thanks. Quote Link to comment 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.