www.webdeveloper.com
Results 1 to 8 of 8

Thread: PHP Caculator of fees and serives

  1. #1
    Join Date
    Oct 2004
    Posts
    5

    Thumbs up PHP Caculator of fees and serives

    Hello evreyone,
    I am EXTREMELY new to PHP, I am still trying to learn where all the resources are yet
    What I am trying to do is to make a caculator that will take and imputed number and caculate a percentage of it as a fee but I also want it to calulate a second fee percentage for if they were to sign up withthe service.
    Be something like this
    Amount of transaction: $1000.00
    Standard Fee: $50.00
    Gold Free: $30.00

    I was just wondering if anyone would know where i could find a torturial or something on how to caculate something like this... or a pre exsisting script i might base it off of.
    Thank you for any assistance

  2. #2
    Join Date
    Sep 2003
    Location
    Portsmouth, UK Occupation: Web Developer
    Posts
    2,602
    something like this

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Percentage Calculator</title>
    </head>

    <body>
    <?php
    if(isset($_POST["cal"])) {
    if(
    $_POST["number"] == "" || !is_numeric($_POST["number"])) {
    echo 
    "You Must Enter A Number</body></html>";
    exit();
    } else {
    $number $_POST["number"];
    $stand = (5/100)*$number;
    $gold = (3/100)*$number;
    echo 
    "Standard: ".$stand."<br />Gold: ".$gold."</body></html>";
    exit();
    }
    }
    ?>
    <form action="<?php echo $PHP_SELF?>" method="post">
    <p>Enter A Value <input type="text" name="number" size="4" /><br />
    <input type="submit" value="Calculate" name="cal" /></p>
    </form>
    </body>
    </html>
    Richard Turner - A Virtual Insight

  3. #3
    Join Date
    Oct 2004
    Posts
    5
    Dang did you make that on the fly?
    that was a fast reply and i have to say i must bow down to your greatness LOL

    yeah its pretty close to what i am thinking... though why does it refreash the page? does it have to?

    And I guess since you here to ask
    if i wanted to add say an equation like 0-1000 = 3% 1000.01 to 5000 = 5% and so forth but still utilize the standard vrs gold vrs.
    I am thinking i would have to do an if statment to seperate the different variables and caculate from there... right? Or do i sound as dumb as i am feeling right now?

  4. #4
    Join Date
    Sep 2003
    Location
    Portsmouth, UK Occupation: Web Developer
    Posts
    2,602
    yes i did make that on the fly, just for you

    it refreshs the page? it shouldnt do maybe your browser doesnt support XHTML fully, thats my only guess do you have a link so i can try?

    im not sure what you mean about 0-1000 = 3% 1000.01 to 5000 = 5%

    do you mean instead of
    PHP Code:
    $number $_POST["number"];
    $stand = (5/100)*$number;
    $gold = (3/100)*$number;
    echo 
    "Standard: ".$stand."<br />Gold: ".$gold."</body></html>"
    you use
    PHP Code:
    $number $_POST["number"];
    if(
    $number <= 1000) {
    $new = (3/100)*$number;
    } elseif(
    $number 1000 && $number 5000) {
    $new = (5/100)*$number;
    } else {
    $new = (7/100)*$number;
    }
    echo 
    "Value: ".$new."</body></html>"
    Richard Turner - A Virtual Insight

  5. #5
    Join Date
    Oct 2004
    Posts
    5
    I am really impressed withyou speed though i am guessing you probably think in PHP and not english right? heheh

    anyhow www.cafegears.com/totuinc/calculator.php is where i posted the codes you left me i did not change them

    when you hit the submit button the page resets to the awnser (in other words the part where you input the info changes to just the awnser) this is excepable i can certainly work with it but i was just cuious why it does. And i am useing IE most recent

    the idea here is sort of like an excrow service (though not what i am doing)
    i have a percentage fee basied on the amount of the trasaction

    soemthing like this
    $0 - 500 i get 5%
    500.01 - 1000 4.5%
    ect ect
    or if htey pay a monthly fee the percentages drop
    and i think thats what you got there though i have to play with and see
    Thank again for your help i do apreciate it... ALOT

  6. #6
    Join Date
    Sep 2003
    Location
    Portsmouth, UK Occupation: Web Developer
    Posts
    2,602
    Originally posted by shatter
    I am really impressed withyou speed though i am guessing you probably think in PHP and not english right? heheh
    hehe something like that

    ok sorry took so long replying was taking timeout watching a dvd, anyway the page doesnt refresh for me, you say you are using IE, may i slap you? try this for me http://www.mozilla.org/firefox/ and download http://www.chrispederick.com/work/firefox/webdeveloper/ this once in firefox, firefox is a browser and that is a brillaint webdev extension for it, and then tell me you still use IE ? , right....

    i think i now understand you meaning of 'refresh', PHP is a server side language therefore is server parsed, meaning the html form sends request to the server, php calculates the values and sends them back in HTML form. the reason why the form does not show on the second page is because of the exit() which tells php to basically end the HTML output here, try removing it and see what it does

    ok so the percentage is kinda like a fee ok try this keep all the same but change the PHP to

    PHP Code:
    <?php
    if(isset($_POST["cal"])) {
    if(
    $_POST["number"] == "" || !is_numeric($_POST["number"])) {
    echo 
    "You Must Enter A Number</body></html>";
    exit();
    } else {
    $number $_POST["number"];
    if(
    $number <= 500) {
    $new = (5/100)*$number;
    } elseif(
    $number 500 && $number <= 1000) {
    $new = (4.5/100)*$number;
    } elseif(
    $number 1000 && $number <= 1500) {
    $new = (4/100)*$number;
    //you could continue here by adding more elseif() continuing the above pattern, but keep the else this is for anything that doesnt fit the above if() or elseif()s
    } else {
    $new = (3.5/100)*$number;
    }
    echo 
    "Transfer After Fees: $".number_format($new2'.''')."</body></html>";
    exit();
    }
    }
    ?>
    Richard Turner - A Virtual Insight

  7. #7
    Join Date
    Oct 2004
    Posts
    5
    Looks great so far
    and when do you want to do free lance work for me

    so far it looks great... except i think we lost the gold and standard part in this or maybe i am missing something... ok i am missing something LOL
    I am tihnking i should just add the
    $stand = (5/100)*$number;
    $gold = (3/100)*$number;
    to the if statments... i am going ot try it out just after dinner but figured i should ask so you have time to post when i find out i am doing it wrong and start pulling my hair out LOL

    Thanks again

  8. #8
    Join Date
    Oct 2004
    Posts
    5
    OOh and i am codeing to my audiance which is 100% IE browsers

    Of course right now the browser is only HTML 1.0 enabled but next month its supposed to go to HTML 4.0... if that even remotely gives you an idea of my nightmare LOL

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles