PHP gods, I need your help please!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alan-l
    Confirmed User
    • May 2003
    • 2477

    #1

    PHP gods, I need your help please!

    Need to fix this in a script and the developer is MIA, any help greatly appreciated. I have this line:

    Code:
    <?php echo $product['niche'][0]; ?>
    which throws whatever I input in the admin area for that field. Like Niche: Latex Fetish.

    However, if I don't input something in that field, the design gets screwed since the divs are floated or whatever, so what I need is just something like

    Code:
    if $product['niche'][0]; is filled, then use it, otherwise add N/A
    I know it's something extremely easy, but I have no idea about PHP, so any help more han appreciated

    Of course, thank you in advance
  • KickAssJesse
    Confirmed User
    • Jul 2008
    • 942

    #2
    PHP Code:
    if ($product['niche'][0]) { echo $product['niche'][0]; } 
    

    Contact - email: jesse~AT~atkcash~DOT~com - Skype: kickassjesse - ICQ: 386185547
    ATK Cash $$$

    Comment

    • alan-l
      Confirmed User
      • May 2003
      • 2477

      #3
      Originally posted by KickAssJesse
      PHP Code:
      if ($product['niche'][0]) { echo $product['niche'][0]; } 
      
      wow, thank you that was fast, but I really need to add something on that field, how do I make it show 'N/A' when field is empty?

      Comment

      • KickAssJesse
        Confirmed User
        • Jul 2008
        • 942

        #4
        PHP Code:
        if ($product['niche'][0]) { echo $product['niche'][0]; } 
        else { echo 'N/A'; } 
        

        Contact - email: jesse~AT~atkcash~DOT~com - Skype: kickassjesse - ICQ: 386185547
        ATK Cash $$$

        Comment

        • Jakez
          Confirmed User
          • Jan 2004
          • 5656

          #5
          Originally posted by KickAssJesse
          PHP Code:
          if ($product['niche'][0]) { echo $product['niche'][0]; } 
          
          PHP Code:
          if ($product['niche'][0]) { echo $product['niche'][0]; } else { echo 'N/A'; } 
          
          [email protected] - jakezdumb - 573689400

          Killuminati

          Comment

          • alan-l
            Confirmed User
            • May 2003
            • 2477

            #6
            thank you guys, that worked like a charm!

            Comment

            • Tempest
              Too lazy to set a custom title
              • May 2004
              • 10217

              #7
              Code:
              if( isset($product['niche'][0]) && $product['niche'][0] != ''){
                  echo $product['niche'][0];
              }else{
                  echo 'N/A';
              }

              Comment

              • blackmonsters
                Making PHP work
                • Nov 2002
                • 20979

                #8
                Originally posted by Tempest
                Code:
                if( isset($product['niche'][0]) && $product['niche'][0] != ''){
                    echo $product['niche'][0];
                }else{
                    echo 'N/A';
                }
                This is better.
                Free Open Source Live Aggregated Cams Script (FOSLACS)

                Comment

                • dissipate
                  The Dirty Frenchman
                  • Nov 2005
                  • 8904

                  #9
                  print !empty($product['niche'][0]) ? $product['niche'][0] : "N/A";

                  Comment

                  • V_RocKs
                    Damn Right I Kiss Ass!
                    • Nov 2003
                    • 32449

                    #10
                    Have we consulted the sanitation department on this yet?

                    Comment

                    • BIGTYMER
                      Junior Achiever
                      • Nov 2004
                      • 17066

                      #11
                      Originally posted by V_RocKs
                      Have we consulted the sanitation department on this yet?
                      As long as product isn't a user submitted variable he's good.

                      Comment

                      Working...