Moron Posted December 4, 2008 Share Posted December 4, 2008 <?php if(!empty($RESULT['PSTU62'])) { echo $RESULT['PSTU62']; echo "<BR>"; } else { } ?> If there is data in the field it echoes it and inserts a break (HTML <BR> tag). But..... if there's nothing in a field, it still inserts a break tag anyway, resulting in too many spaces between entries. Ideas? ??? Quote Link to comment https://forums.phpfreaks.com/topic/135560-solved-else-do-nothing-not-working/ Share on other sites More sharing options...
cpd Posted December 4, 2008 Share Posted December 4, 2008 You dont need an else statement on that loop. All you want to do is echo out what youve done so you just need <?php if(!empty($RESULT['PSTU62'])) { echo $RESULT['PSTU62']."<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135560-solved-else-do-nothing-not-working/#findComment-706207 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 Just adding on, I would check to see if it exists first. <?php if(isset($_RESULT['PSTU62']) && !empty($RESULT['PSTU62'])) { echo $RESULT['PSTU62']."<br />"; } ?> That way it does not display the index undefined error when that value isn't there. Quote Link to comment https://forums.phpfreaks.com/topic/135560-solved-else-do-nothing-not-working/#findComment-706210 Share on other sites More sharing options...
Moron Posted December 4, 2008 Author Share Posted December 4, 2008 You dont need an else statement on that loop. All you want to do is echo out what youve done so you just need <?php if(!empty($RESULT['PSTU62'])) { echo $RESULT['PSTU62']."<br />"; } ?> Thanks, but I'm getting the same result, a "<BR>" inserted even when the field is empty. Using your example, my code now reads: <?php if(!empty($RESULT['PSTU62'])) { echo $RESULT['PSTU62']."<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135560-solved-else-do-nothing-not-working/#findComment-706214 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 A side note even a whitespace is considered not empty. <?php if(isset($_RESULT['PSTU62']) && !empty(trim($RESULT['PSTU62']))) { echo $RESULT['PSTU62']."<br />"; } ?> The trim function will remove any whitespaces. Here is another variation, that may be better suited that way you the variable exist if not it is null you then use the is_null function to check. And it is trimmed in the definition. <?php $pst = isset($_RESULT['PSTU62'])?trim($_RESULT['PSTU62']):null; if(!is_null($pst) && $pst != "") { echo $RESULT['PSTU62']."<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135560-solved-else-do-nothing-not-working/#findComment-706222 Share on other sites More sharing options...
.josh Posted December 4, 2008 Share Posted December 4, 2008 If you are getting 2 blank lines when it's true and 1 blank line when it's false, you have a blank line being output somewhere else. Maybe an extra line after your closing php tag ?> or something. Somewhere other than the else. Quote Link to comment https://forums.phpfreaks.com/topic/135560-solved-else-do-nothing-not-working/#findComment-706228 Share on other sites More sharing options...
Moron Posted December 4, 2008 Author Share Posted December 4, 2008 A side note even a whitespace is considered not empty. <?php if(isset($_RESULT['PSTU62']) && !empty(trim($RESULT['PSTU62']))) { echo $RESULT['PSTU62']."<br />"; } ?> The trim function will remove any whitespaces. Here is another variation, that may be better suited that way you the variable exist if not it is null you then use the is_null function to check. And it is trimmed in the definition. <?php $pst = isset($_RESULT['PSTU62'])?trim($_RESULT['PSTU62']):null; if(!is_null($pst) && $pst != "") { echo $RESULT['PSTU62']."<br />"; } ?> Your second example seems to be working for me. Adapting it to my code I'm using: <?php $message62 = isset($RESULT['PSTU62'])?trim($RESULT['PSTU62']):null; if(!is_null($message62) && $message62 != "") { echo $RESULT['PSTU62']."<br />"; } $message63 = isset($RESULT['PSTU63'])?trim($RESULT['PSTU63']):null; if(!is_null(message63) && message63 != "") { echo $RESULT['PSTU63']."<br />"; } $message64 = isset($RESULT['PSTU64'])?trim($RESULT['PSTU64']):null; if(!is_null(message64) && $message64 != "") { echo $RESULT['PSTU64']."<br />"; } ?> ...etc..... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/135560-solved-else-do-nothing-not-working/#findComment-706233 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.