1

I am using queries like this to pull in information from a database:

<p><strong>Show Description:</strong><br/><?php echo cimy_uef_sanitize_content(get_cimyFieldValue(1, 'show-description')); ?></p>

Is there any way to put the title (Show Description) into the PHP string and then, if the PHP field value is empty, to not show anything?

I think it would involve a PHP if/else statement, but I am not sure what the code should look like.

Thanks Zach

3 Answers 3

2

It is hard without seeing the code for those functions, but at a guess:

if (get_cimyFieldValue(1, 'show-description') != '')
    {
    echo "<p><strong>Show Description:</strong></p>" . cimy_uef_sanitize_content(get_cimyFieldValue(1, 'show-description'));
    }

Should work

Sign up to request clarification or add additional context in comments.

Comments

1

You can use PHP's empty() function for this purpose -

<p>
    <?php 
        $data = cimy_uef_sanitize_content(get_cimyFieldValue(1, 'show-description')); 

        if( !empty($data) )
        {
            echo "<strong>Show Description:</strong><br/>";
            echo $data;
        }
    ?>
</p>

According to the documentation, this function will return true if the $data variable is either -

1. "" (an empty string)
2. 0 (0 as an integer)
3. 0.0 (0 as a float)
4. "0" (0 as a string)
5. NULL
6. FALSE
7. array() (an empty array)
8. var $var; (a variable declared, but without a value in a class)

Comments

0

If I understood You correctly, You need something like this:

<?php $title = cimy_uef_sanitize_content(get_cimyFieldValue(1, 'show-description')); ?>
<?php if(!empty($title)): ?>
<p>
    <strong>Show Description:</strong><br/>
    <?php echo $title; ?>
</p>
<?php endif; ?>

Not compiled, so there can be errors in code, but you get the point...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.