Is it possible to have three && operators in PHP

Discussion in 'PHP' started by Justcars.ie, Oct 8, 2009.

  1. #1
    Hi guys,

    I have a list of if statements for a search on my site. What im wondering is if this is possible


    if ($x==' ' && $y==' ' && isset($z))
         { 
            
    	 ///////// do mysql query
    
    	 }
    Code (markup):
    Also tried it like this

    if ($x==' ' && ($y==' ' && isset($z)))
         { 
            
    	 ///////// do mysql query
    
    	 }
    Code (markup):

    Hope somebody can help.

    Cheers!
     
    Justcars.ie, Oct 8, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sure it's possible. Have you not tested it? You can have as many conditionals as you want.
     
    premiumscripts, Oct 8, 2009 IP
  3. Justcars.ie

    Justcars.ie Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    cheers for the response,

    it seems to be a problem when i have this

    function get_results($x, $y, $z){
    
    if ($x==' ' && $y==' ' && isset($z))
         { 
            
    	 ///////// do mysql query
    
    	 }
    
    elseif ($x==' ' && $y==' ')
         { 
            
    	 ///////// do mysql query
    
    	 }
    
    }
    Code (markup):
    Anybody any ideas?

    Cheers
     
    Justcars.ie, Oct 8, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What is the problem exactly? You'll have to tell us.

    Additionally, $z is always set as it's an argument to your function. You should probably use !empty($z)
     
    premiumscripts, Oct 8, 2009 IP
  5. Justcars.ie

    Justcars.ie Peon

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Cheers for that!

    My bad.... It was the !empty that was stopping it from working.

    Thanks very much..
     
    Justcars.ie, Oct 8, 2009 IP