Quick PHP Question.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jdoughs
    Confirmed User
    • Mar 2004
    • 5794

    #1

    Quick PHP Question.

    I've got a check to see if it's a certain producttype (dog), and if so, something fits. Question is, can I have it be 'dog' and 'cat' and still have it as a line and not going into a if/else?

    <-- Total noob, just learning.

    Thanks in advance and Happy New Year.

    PHP Code:
    <?php if($this->product->productType == 'dog') { ?>        ruff ruff ruff            <?php } ?>
    Code:
    <?php if($this->product->productType == 'dog') { ?>		ruff ruff ruff			<?php } ?>
    LinkSpun - Premier Adult Link Trading Community - ICQ - 464/\281/\250
    Be Seen By New Webmasters/Affiliates * Target out webmasters/affiliates based on niches your sites are for less than $20 a month.
    AmeriNOC - Proudly hosted @ AmeriNOC!
  • MrGusMuller
    Confirmed User
    • Oct 2010
    • 1262

    #2
    Sorry, but I havent understood ur question.
    I have a lousy english.
    But you have a variable set to be "dog" how can it be "dog" and "cat" at the same time?

    <?php if($this->product->productType == 'dog' or $this->product->productType == 'cat') { ?>
    StagCMS - Adult CMS - user friendly adult content management system - speed up your websites with no SQL connections
    ICQ: 63*23*43*113

    Comment

    • Jdoughs
      Confirmed User
      • Mar 2004
      • 5794

      #3
      Yes that is what I meant "OR".

      If it is dog or cat. (could be both) I guess, bowls, toys, I don't know

      THANKS!
      LinkSpun - Premier Adult Link Trading Community - ICQ - 464/\281/\250
      Be Seen By New Webmasters/Affiliates * Target out webmasters/affiliates based on niches your sites are for less than $20 a month.
      AmeriNOC - Proudly hosted @ AmeriNOC!

      Comment

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

        #4
        if( item==dog or item==cat ){ do stuff }
        Don't let greediness blur your vision | You gotta let some shit slide
        icq - 441-456-888

        Comment

        • cooldude7
          Confirmed User
          • Nov 2009
          • 4306

          #5
          Originally posted by grumpy
          if( item==dog or item==cat ){ do stuff }
          do stuff with whom ?

          Comment

          • Sexgenoten
            Registered User
            • Dec 2010
            • 85

            #6
            I'd start by seperating your scripting layer from you presentation layer.

            Perhaps using a ''switch" could help you as well.

            $var = 'dog';

            switch( $var ){
            case 'dog':
            echo "woef woef";
            break;

            case 'cat':
            echo "miauw";
            break;

            default:
            echo "no cat or dog found";

            }
            Last edited by Sexgenoten; 01-02-2011, 06:57 AM.

            Comment

            • bl4h
              Confirmed User
              • Jul 2006
              • 1282

              #7
              wtf ? am I missing something here


              Code:
              if($this->product->productType == "dog" || $this->product->productType == "cat") { }
              the two pipes between them means "OR".

              || = OR
              && = AND

              I mean I wouldnt do it that way but that answer your question about and and or.

              Comment

              • Adultlexicon
                Confirmed User
                • Aug 2003
                • 816

                #8
                Check PHP.net its full of examples

                Comment

                • r0bman
                  Confirmed User
                  • Sep 2010
                  • 38

                  #9
                  Originally posted by bl4h
                  wtf ? am I missing something here


                  Code:
                  if($this->product->productType == "dog" || $this->product->productType == "cat") { }
                  the two pipes between them means "OR".

                  || = OR
                  && = AND

                  I mean I wouldnt do it that way but that answer your question about and and or.
                  This is the correct way unless you are comparing more than a few product types (Cat, Dog, Horse, Pig) If so, use the switch statement.

                  Comment

                  Working...