Extremely basic PHP help needed.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chodadog
    Confirmed User
    • Apr 2002
    • 9736

    #1

    Extremely basic PHP help needed.

    Okay, i've already got this..

    PHP Code:
    <?php echo $HTTP_GET_VARS['w']; ?>
    Which is fine, but i'd like some sort of if/else thingy. Example, if w is null (index.php?w=), then make w=9999999 or if the w variable isn't passed at all (index.php), then make w=9999999.

    Hopefully that actually makes sense. I'm so very clueless when it comes to this shit.
    26 + 6 = 1
  • psyko514
    See sig. Join Epic Cash.
    • Oct 2002
    • 22366

    #2
    PHP Code:
    <? if (!isset($w)) { $w = 999999; } ?>

    Bad Girl Bucks
    - 50% Revshare through CCBill.
    Promote BrandyDDD, Pixie's Pillows, Action Allie and more!

    Phoenix Forum Pics | Webmaster Access Montreal pics
    email: psyko514(a)gmail.com | icq: 214-702-014

    Comment

    • SilverTab
      Confirmed User
      • Nov 2001
      • 5060

      #3
      If w is a variable you can check with

      if (empty($w))
      {
      ...
      }
      else
      {
      ...
      }

      not sure if I get what you mean tough!
      mmm my sig was too big... no more cool animation
      but hey still! need php? ICQ: 94586959

      Comment

      • chodadog
        Confirmed User
        • Apr 2002
        • 9736

        #4
        SilverTab, thanks. That's exactly what i was looking for. psyko, thanks too, but not exactly sure what to do with what you gave me! But thanks anyways. Sorry for being so unclear in the first place.
        26 + 6 = 1

        Comment

        • SilverTab
          Confirmed User
          • Nov 2001
          • 5060

          #5
          Np !...glad I could be helpful
          mmm my sig was too big... no more cool animation
          but hey still! need php? ICQ: 94586959

          Comment

          • psyko514
            See sig. Join Epic Cash.
            • Oct 2002
            • 22366

            #6
            Chodadog... the isset() function checks to see if the variable has been set (if it has a value). if so, it gives a result of TRUE.

            the code i posted checks to see if W has been given a value, and if not, it gives W a value of 99999 or whatever else you want.

            i posted it in one line, but it could be broken into several lines

            PHP Code:
            <?php
            if (!isset($w)) {
               $w = 999999; 
            } 
            ?>
            the empty() function does more or less the same thing... except that if W = 0, isset() will return TRUE but empty() will return FALSE

            Bad Girl Bucks
            - 50% Revshare through CCBill.
            Promote BrandyDDD, Pixie's Pillows, Action Allie and more!

            Phoenix Forum Pics | Webmaster Access Montreal pics
            email: psyko514(a)gmail.com | icq: 214-702-014

            Comment

            • SilverTab
              Confirmed User
              • Nov 2001
              • 5060

              #7
              Originally posted by psyko514

              the empty() function does more or less the same thing... except that if W = 0, isset() will return TRUE but empty() will return FALSE
              Yup..Always more than one ways to get to the same result in programming
              mmm my sig was too big... no more cool animation
              but hey still! need php? ICQ: 94586959

              Comment

              • Cogitator
                Confirmed User
                • Feb 2002
                • 672

                #8
                I always create a function like:
                PHP Code:
                <?
                function GetValue($var, $default) {
                    if (isset($var) {
                        return $var;
                    } else {
                        return $default;
                    }
                }
                ?>
                
                // you would use it as follows:
                
                <?
                echo GetValue($w, 999999);
                ?>
                - this space intentionally left blank -

                Comment

                • Bad B0y
                  Confirmed User
                  • Aug 2002
                  • 160

                  #9
                  another way(not tested btw) just cuz i have nothing better to do after i've watered the plants and taken my special pills.

                  $w = empty($w) ? 999999 : $w;

                  Comment

                  Working...