Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Switch statement

    Hello,

    Ive been having a big problem here is the thread . So for the last 2 weeks ive been trying to figure something. I am a newbie in PHP coding, but i am willing to learn and work hard. I read that having a "Switch Statement" might help, however, i am now completly lost as to how that works, can someone help me? I was reading on php.net, but that didnt help that much, does anybody have any other ideas?

    thank you very much

  • #2
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just a basic switch statement
    PHP Code:
    <?php
    $cat 
    $_GET['cat'];
    switch(
    $cat){

    case 
    "contact";
    echo 
    "Contact Us";
    break;

    case 
    "join";
    echo 
    "Join our Site!";
    break;

    default;
    echo 
    "Welcome to our site!";
    break;
    }
    ?>
    Now the cases are what to do 'in case' variable $cat equals "contact" thus case "contact"; and the same for "join." Obviously, default is what to do in case none of the cases match.

    Hope this helps.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #3
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Typos:
    Code:
    case "contact";
    
    echo "Contact Us";
    
    break;
    Should be
    Code:
    case "contact":
    
    echo "Contact Us";
    
    break;
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #4
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Really?

    I've never got errors with case "contact";

    Thanks anyway.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Originally posted by SDP2006
    Really?

    I've never got errors with case "contact";

    Thanks anyway.
    Yes really. Your switch statement is incorrect. You should consult the PHP manual.

    http://us4.php.net/manual/en/control...res.switch.php
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, thanks for the heads up guys
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Posts
    245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    k thanx....but is the switch what i need for my problem my problem look at my last post. So would this solve my problem...

    thanx again


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •