Results 1 to 6 of 6

Thread: Switch Statements problem

  1. #1
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Switch Statements problem

    hello, this is my first post so thanks for reading up on it.

    i'm having issues with my 1st switch statement, can you tell me what looks incorrect in my code?

    what i'm trying to accomplish is getting the final total of price plus state tax per state.

    PHP Code:

    <?php
      $price 
    == 20.00
      $cust_state 
    == "TX";
    ?>     
         
                  
    <?php
         
    switch ( $cust_state )
              {
                   case 
    "OR":
                    
    $salestax 0.5;
                    break;

                   case 
    "TX":
                    
    $salestax 0.3;
                    break;

                   case 
    "CA":
                    
    $salestax 1;
                    break;
          
                   default:
                    
    $salestax 0.1;
                    break;
    }

    $final_price $price $salestax;
    ?>

    <?php echo "the final total is $final_price"?>
    I'm getting back "the final total is 0"
    Last edited by Snookerman; 04-22-2009 at 08:24 AM. Reason: added [php] tags and “Resolved” prefix

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Try this:
    PHP Code:
    <?php
      $price 
    20.00
      $cust_state 
    "TX";
    ?>
    Good luck!

  3. #3
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Snookerman View Post
    Try this:
    PHP Code:
    <?php
      $price 
    20.00
      $cust_state 
    "TX";
    ?>
    Good luck!
    i'm assuming you didn't mean to leave out that first ";"

    i did try your method, it was actually my first thought too, but i'm still getting back the same result.

  4. #4
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Try this then:
    PHP Code:
    {
                   case 
    "OR":
                    
    $salestax 0.5;
                    break;

                   case 
    "TX":
                    
    $salestax 0.3;
                    break;

                   case 
    "CA":
                    
    $salestax 1;
                    break;
          
                   default:
                    
    $salestax 0.1;

    Good luck!

  5. The Following User Says Thank You to Snookerman For This Useful Post:

    x0prah_Winfr3yx (01-25-2009)

  6. #5
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    thank you, i realize that i was mistyping a variable. wonder how many times that happens?

    thanks for your help

  7. #6
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    You're welcome, glad to help!

    I'd like to recommend Notepad++ since it has a nice feature that highlights all instances of a word or variable when you mark it which is really helpful when checking for typos.

    You can go to your first post in this thread, click then click Go Advanced and add the Resolved prefix to the thread title. This will let other users know the problem has been solved.

    Good luck with your site!

Bookmarks

Posting Permissions

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