Need PHP function and cal

Discussion in 'PHP' started by gkz, Dec 22, 2007.

  1. #1
    I need a PHP function and calculation for the following-

    web hosting:
    $3, $6 or $12 monthly

    plus $5 each month for each extra ordered (e.g. more space, bandwidth, etc... all the extras are charged at a flat $5 each per month).

    The customer selects either the 3, 6 or 12 dollar plan and also selects the extras that they want.

    The code needs to calculate their monthly charge, plus add $5 for each extra that they chose based on their plan.

    What would be the best way to code this?

    Thanks
    gkz
     
    gkz, Dec 22, 2007 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    there are two options

    Either you can use javascript or PHP

    javascript is not good as all code is visible to client

    so better use php

    Regards

    Alex
     
    kmap, Dec 22, 2007 IP
  3. wolfson

    wolfson Active Member

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #3
    the best way to code this is AJAX / PHP
     
    wolfson, Dec 22, 2007 IP
  4. gkz

    gkz Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes it needs to be in PHP.

    So far I have this but need to define the arrays somehow so the $5 for each extra is added properly, plus the plan cost.


    // Calculate extras
    if (array_key_exists('extras', $_POST)) {
    $extras_array = $_POST['extras'];
    foreach ($extras_array as $extras)
    $total_extras = $extras += 5;
    }
    // Calculate fee
    if (array_key_exists('plan', $_POST)) {
    $plan['0'] = '3';
    $plan['1'] = '6';
    $plan['2'] = '12';
    foreach ($plan_array as $plan)
    $fee = $total_extras + $plan;
    echo "<p>Monthly subscription fee: $$fee</p>";
    }

    Am still learning so have probably got things mixed up.

    Thanks
    gkz
     
    gkz, Dec 22, 2007 IP
  5. wolfson

    wolfson Active Member

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #5
    I have a done a script that shows how it works with AJAX/PHP. PM me if you want to see because i don't have permission to submit links.
     
    wolfson, Dec 22, 2007 IP
  6. gkz

    gkz Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Any help with this PHP coding would be much appreciated. I need to somehow add the price for each 'extra' that is selected and add it to the cost of the monthly plan.

    Thanks
    gkz
     
    gkz, Dec 22, 2007 IP
  7. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #7
    hey you should pay someone and get the work done

    Regards

    Alex
     
    kmap, Dec 22, 2007 IP
  8. gkz

    gkz Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks to everyone for their help, much appreciated.

    Ta
    gkz
    :)
     
    gkz, Dec 31, 2007 IP