PHP coders - quick question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fusionx
    Confirmed User
    • Nov 2003
    • 4618

    #1

    PHP coders - quick question

    How do I do this:

    IF $_GET['cat'] = 0 OR $_GET['cat'] IS NULL
    myCat = 0
    else
    myCat = $_GET['cat']
    END IF

    Basically, if there is a request var called "cat" and it is zero, null, or if it doesn't even exist, set a var myCat to zero.
    Otherwise, set the var to whatever it currently contains.

    Thanks in advance!
  • Aric
    Confirmed User
    • Sep 2002
    • 1209

    #2
    if(!empty($_GET['cat']))
    $myCat = $_GET['cat'];
    else
    $myCat = defaultValue;
    Awesome cloud hosting by DigitalOcean

    Comment

    • fusionx
      Confirmed User
      • Nov 2003
      • 4618

      #3
      Originally posted by Aric
      if(!empty($_GET['cat']))
      $myCat = $_GET['cat'];
      else
      $myCat = defaultValue;
      Isl ?cat=0 still considered empty?

      Comment

      • Aric
        Confirmed User
        • Sep 2002
        • 1209

        #4
        as far as I know in newer versions of PHP, 0 is empty.. you can also use

        !isset($_GET['cat']) if !empty() doesn't work out for ya
        Awesome cloud hosting by DigitalOcean

        Comment

        • fusionx
          Confirmed User
          • Nov 2003
          • 4618

          #5
          Thanks very much! It works well.

          Comment

          • richard
            Confirmed User
            • Feb 2001
            • 543

            #6
            empty($_GET["cat"]) ? ($myCat=0) : ($myCat=$_GET["cat"]);

            That's basically what i use.

            Comment

            • hyper
              Confirmed User
              • Mar 2002
              • 5294

              #7
              i use isset

              Comment

              • opflix
                Confirmed User
                • Jul 2002
                • 1428

                #8
                Originally posted by Aric
                if(!empty($_GET['cat']))
                $myCat = $_GET['cat'];
                else
                $myCat = defaultValue;

                aric, do u have a site or offer programming services? lmk... i have a project if u r available - thanks!

                ...
                Social Escrow - Buying & Selling Accounts? Contact Me | Social Escrow IG

                Comment

                • grumpy
                  Too lazy to set a custom title
                  • Jan 2002
                  • 9870

                  #9
                  if($_GET['cat'] < 1){$_GET['cat']=0}
                  Don't let greediness blur your vision | You gotta let some shit slide
                  icq - 441-456-888

                  Comment

                  • woj
                    <&(©¿©)&>
                    • Jul 2002
                    • 47882

                    #10
                    if cat is a numeric value, like a category id or something, you can do:
                    $myCat=intval($_GET['cat']);
                    Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
                    Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
                    Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

                    Comment

                    • Voodoo
                      ♥ ♦ ♣ ♠
                      • Sep 2002
                      • 10600

                      #11
                      WHEN WILL YOU LEARN!?!?!?!? "Quick Questions" NEVER have "quick answers".

                      "I'm selflessly supporting the common good, but only coincidentally looking out for No.1."

                      Comment

                      Working...