Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Using if for non-blank data

    I have text field in a database that will either be blank (Null) depending upon if the user completes a text area in form.

    I'd like to show a link based on that field only if the field has data in it. I had thought this would work, but its not:

    Code:
    <?php if($custom_rules != " "){ ?>
    html to custom link here
    <? } ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Use if (empty($var)) or (if $var > '')

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    you can use

    PHP Code:
    <?php
    if($var){
        
    // $var is NOT empty
    } else {
        
    // $var is empty
    }
    ?>
    But I like the empty function better
    -

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Quote Originally Posted by Leppy View Post
    you can use

    PHP Code:
    <?php
    if($var){
        
    // $var is NOT empty
    } else {
        
    // $var is empty
    }
    ?>
    But I like the empty function better
    That so does not work.

  • #5
    New Coder
    Join Date
    Jul 2007
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    really? I've tested it in few script and when the var is empty, it is like the var = false, no?
    -


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •