Php help-few 'if else' statements

Discussion in 'PHP' started by ItamarP, Jul 4, 2009.

  1. #1
    i wrote a code with few if&else sepperate statements

    1)if...echo blablalba
    else.. blablaba

    1)if...echo blablalba
    else.. blablaba

    i want that the moment the first " if " statement will be executed only the first echo statement will be printed

    who can i do it ? what funtion or script do i have to use?

    thanks in advance
     
    ItamarP, Jul 4, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    sorry what do you mean by

    "i want that the moment the first " if " statement will be executed only the first echo statement will be printed"
     
    wd_2k6, Jul 4, 2009 IP
  3. dorinn

    dorinn Active Member

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #3
    if u mean "if 1st cond is valid then dont go try to 2nd if" use
    if...echo blablalba
    else {.. blablaba

    if...echo blablalba
    else.. blablaba
    }
    this would mean the blabla from first if's else is executed then 2nd if is tested
     
    dorinn, Jul 4, 2009 IP
  4. q111z

    q111z Guest

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can do it .. example :

    
    <?
    if ( ) echo "Any thing";
    Elseif () echo "sss";
    else { Echo "Flase statments": }
    ?>
    
    PHP:
     
    q111z, Jul 5, 2009 IP
  5. Mr.Comedy

    Mr.Comedy Banned

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?
    if ( ) echo "Any thing";
    Elseif () echo "sss";
    else { Echo "Flase statments": }
    ?>

    should do the trick
     
    Mr.Comedy, Jul 5, 2009 IP
  6. alfa_375

    alfa_375 Active Member

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Tricky if & else statements. But like q111z is mention it should work. Update us on this if you solved your problem please.
     
    alfa_375, Jul 5, 2009 IP
  7. ItamarP

    ItamarP Member

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    ofcouse i used "elseif" but i want that when the first if is vaild the code will stop

    thanks
     
    ItamarP, Jul 5, 2009 IP
  8. syariscrewz

    syariscrewz Banned

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    this is example i made for you to understand if else if else .

     
    syariscrewz, Jul 5, 2009 IP
  9. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #9
    That's the whole point of an if statement, if the condition is valid it executes the statement and stops there, it won't bother looking at the else if or else.
     
    wd_2k6, Jul 5, 2009 IP