Jump to content

[SOLVED] "Else Do Nothing" not working


Moron

Recommended Posts

<?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?

 

???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 />"; 
}

?>

Link to comment
Share on other sites

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 />"; 
}
?>

Link to comment
Share on other sites

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!

 

:)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.