Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
  1. #11
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by Invent View Post
    Switches ftw (I just read that Caleb suggested using them, I find them much easier to use for a script like this).
    I think they are a better alternative when parsing types, EX in this script would be the method that you are using to perform the calculation.

    Or verifying that an option in a submission form is actually an option provided, and not someone submitting something that is either malicious, or just not acceptable.


  2. #12
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Could of at least put the buttons on the page and made it abit interesting, but celebs right with the switch & case method, its how I'd do it and many others.
    Hi, names James. I am a web developer.

  3. #13
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    I think you should make it into an actual calculator shape wud be a good idea

  4. #14
    Join Date
    Apr 2008
    Location
    England.
    Posts
    1,324
    Tokens
    0

    Latest Awards:

    Default

    Just echo what they put in.. say the fields were call blah 1 and blah 2.

    PHP Code:
    elseif($submit){
    $sum=$blah+$blah1;
    echo 
    "$blah+$blah1=$sum"

  5. #15
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Even easier:

    PHP Code:
    <?php
    $number1 
    $_POST["number1"];
    $number2 $_POST["number2"];
    $type $_POST["type"];

    switch( 
    $type )
    {
        case 
    "+"$calculation $number1 $number2; break;
        case 
    "-"$calculation $number1 $number2; break;
        case 
    "/"$calculation $number1 $number2; break;
        case 
    "*"$calculation $number1 $number2; break;
        default: 
    "You ain't doin math boy.";
    }

    echo 
    $number1 " " $type " " $number2 " = " $calculation;
    ?>

  6. #16
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    Even easier:

    PHP Code:
    <?php
    $number1 
    $_POST["number1"];
    $number2 $_POST["number2"];
    $type $_POST["type"];

    switch( 
    $type )
    {
        case 
    "+"$calculation $number1 $number2; break;
        case 
    "-"$calculation $number1 $number2; break;
        case 
    "/"$calculation $number1 $number2; break;
        case 
    "*"$calculation $number1 $number2; break;
        default: 
    "You ain't doin math boy.";
    }

    echo 
    $number1 " " $type " " $number2 " = " $calculation;
    ?>
    Haha, love it.

Page 2 of 2 FirstFirst 12

Posting Permissions

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