isEMPTY

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geraldjr30
    New Member
    • Jan 2009
    • 60

    isEMPTY

    hi,

    i have the following:

    Code:
    <?php
    ...
    if(empty($_GET['SFT']) AND empty($_GET['fac']))
    {
    echo "one";
    }
    elseif(empty($_GET['SFT']) AND isset($_GET['fac']))
    {
    echo "two";
    }
    elseif(isset($_GET['SFT']) AND isset($_GET['fac']))
    {
    echo "three";
    }
    else
    {
    echo "four";
    }
    ...
    for some reason "three" is show for the following url:


    i think i need to add another else or something because seems like it should be displaying "four". i just need something to handle cases in which the fac is empty or no value, as seen in my url here.

    thanks in advance,
    geebee
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by geraldjr30
    for some reason "three" is show for the following url:
    http://localhost/REC.php?count=tuesd...20-%204PM-12AM
    which is totally correct, both values (fac & SFT) are set, thus fulfilling condition 3. that one of them doesn't have a value is no concern of isset().

    you could simplify that by
    Code:
    isset($_GET['SFT'], $_GET['fac'])
    Originally posted by geraldjr30
    i just need something to handle cases in which the fac is empty or no value, as seen in my url here.
    Code:
    !$_GET['fac'] && $_GET['SFT']

    Comment

    • geraldjr30
      New Member
      • Jan 2009
      • 60

      #3
      how can i handle the "fac=" part?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by geraldjr30
        how can i handle the "fac=" part?
        what do you mean by that?

        Comment

        • geraldjr30
          New Member
          • Jan 2009
          • 60

          #5
          would i handle it with ISNULL for cases like this?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            either use empty($_GET['fac']) or !$_GET['fac']

            Comment

            • TheServant
              Recognized Expert Top Contributor
              • Feb 2008
              • 1168

              #7
              Can I recommend looking at the isset() function. It's good for $_POST and $_GET variables.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Originally posted by TheServant
                Can I recommend looking at the isset() function. It's good for $_POST and $_GET variables.
                that's right to first check, whether the variable you want to use actually exists. nevertheless, isset() tells you nothing about the variable's value.

                Comment

                • geraldjr30
                  New Member
                  • Jan 2009
                  • 60

                  #9
                  is there such thing as NOT empty($_GET['fac'])?

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Originally posted by geraldjr30
                    is there such thing as NOT empty($_GET['fac'])?
                    empty() returns a boolean value (true or false) depending on the variable. You check if it's empty like so:

                    Code:
                    if( empty ($var) )
                    {
                        ...
                    }
                    You can check if it's not empty by using the exclamation (!) symbol prior to the statement (this checks if a function returns false).
                    Code:
                    if( ! empty ($var) )
                    {
                        ...
                    }
                    Hope this helps.

                    Comment

                    • geraldjr30
                      New Member
                      • Jan 2009
                      • 60

                      #11
                      thanks... that helps!!

                      Comment

                      • Markus
                        Recognized Expert Expert
                        • Jun 2007
                        • 6092

                        #12
                        Originally posted by geraldjr30
                        thanks... that helps!!
                        No problamo.

                        See ya around,
                        Markus.

                        Comment

                        Working...