NoDoze Posted May 5, 2009 Share Posted May 5, 2009 if (isset($row['murl'])) echo "<a href=".$row['murl'] . ">more info</a>"; else echo "<a href=".$row['mhover'] . ">more info</a>"; I think this is correct....but if the variable isn't present, it's NOT showin the mhover URL....what am I doing wrong? I'm trying to do... If variable is pesent in DB do THIS ELSE Do THAT Thanks! Link to comment https://forums.phpfreaks.com/topic/156872-solved-if-elsethe-bain-of-my-existance-grrrhehe/ Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 Well a variable will always be set unless the DB doesn't have that column. Try using empty instead. Link to comment https://forums.phpfreaks.com/topic/156872-solved-if-elsethe-bain-of-my-existance-grrrhehe/#findComment-826363 Share on other sites More sharing options...
nankoweap Posted May 5, 2009 Share Posted May 5, 2009 as ken2k7 noted, as long as you select the column $rows['murl'] will always be set. you need to know its value. try using is_null and empty. something like... if (is_null($row['murl']) || empty($row['murl'])) { ... } else { ... } Link to comment https://forums.phpfreaks.com/topic/156872-solved-if-elsethe-bain-of-my-existance-grrrhehe/#findComment-826418 Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 First of all if is_null($var) is true, then empty($var) is true. There's no need to call both, especially when it's an OR statement. Link to comment https://forums.phpfreaks.com/topic/156872-solved-if-elsethe-bain-of-my-existance-grrrhehe/#findComment-826482 Share on other sites More sharing options...
nankoweap Posted May 5, 2009 Share Posted May 5, 2009 First of all if is_null($var) is true, then empty($var) is true. There's no need to call both, especially when it's an OR statement. yep. just re-read the man page for empty. sum-bitch. been coding redundancy into my first php app already. thanks for the info. gonna have to fix that in the next iteration. Link to comment https://forums.phpfreaks.com/topic/156872-solved-if-elsethe-bain-of-my-existance-grrrhehe/#findComment-826689 Share on other sites More sharing options...
NoDoze Posted May 5, 2009 Author Share Posted May 5, 2009 Cool! That did the trick! Thanks! Link to comment https://forums.phpfreaks.com/topic/156872-solved-if-elsethe-bain-of-my-existance-grrrhehe/#findComment-826761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.