Results 1 to 11 of 11

Thread: calculator

  1. #1

    * calculator

    Hey, Im building a website for my work. And they own a Travel Company. I want to do a PHP or HTML thing where they can click how many people are traveling and where to and it comes up with a answer As In How much it will cost. If anyone can code one or knows where i can get one would really help

    23 People
    To London
    From Leeds
    = £230

    See what i mean? I want it so when they click or type the opions they want it will have a calculat button at the bottem and tell them the price


    Cheers Ricky

  2. #2
    Join Date
    Feb 2006
    Location
    Pittsburgh PA
    Posts
    289
    i would start looking into javascript, I want to do the same thing, but i cant really find any good information on it. however, I have seen what your talking about done in java, but i dont have to code =/

  3. #3
    Yeah, Java And php arnt really my thing i only know HTML and how to edit PHP.. lol So im a bit noobbish on that

  4. #4
    Join Date
    Oct 2006
    Posts
    44
    Whether you want to use a client-side language like javascript, or a server side technology like php or ruby will depend on your needs. If your prices are fixed then javascript can offer a faster user experience, but isn't as flexible as the server technologies. PHP and the other server side technologies will allow you to store prices in a database and update them in a single place, which makes ongoing administration easier. The price you pay is you need more resources to run server side technologies. AJAX would give you a good compromise between the two options, but will cost more to set up.

    There are a number of places you can go to find scripts on the web. Just do a Google search for 'php scripts' or the like and you'll find plenty of sites that have scripts. I haven't used any of these sites, so I can't offer any recomendations. But I will warn you not to use any pre made script if you can't understand the php well enough to be sure there aren't any security holes.

    I can't really say what it would cost you to have it done either. The old maxim about 'you get what you pay for' applies. You don't want to over pay, but you don't want shoddy, buggy scripts either.
    Andrew
    Spry VPS Hosting cPanel VPS, Plesk VPS, Webmin VPS, Shared, Domain Registration, Dedicated and Colo
    VPSLink Cheap VPS accounts CentOS, Fedora 4/5/6, RHEL, Gentoo, Debian, Ubuntu -- Dapper/Edgy, Slackware, OpenSUSE, LAMP + Ruby pre-installed available

  5. #5
    cheers andrew Ill keep that in mind

  6. #6
    Join Date
    Jan 2003
    Location
    USA, FL
    Posts
    251
    Rick if you know the prices of the ticket then here is a simple script.
    This script is just and example and is not for production use.
    This is the longer, hardcoded away of doing it but it could be done by database which would be easier to maintain and change prices like spryandrew explained.

    Thank you and have a good day

    Code:
    <?php
    
    $get_to = $_POST['to'];
    $get_from = $_POST['from'];
    $get_ppl = $_POST['ppl'];
    
    if(isset($get_to) && isset($get_from) && isset($get_ppl)){
    if($get_to == 'london' && $get_from='leads'){
    $price = $get_ppl * 200;
    echo 'Cost is: '.$price.'<br />';
    }
    }
    
    ?>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    To:<select name="to">
    <option value="london">London</option>
    </select>
    From: <select name="from">
    <option value="leads">Leads</option>
    </select>
    People: <input type="text" name="ppl" />
    <input type="submit" value="Submit" />
    </form>

  7. #7
    Quote Originally Posted by Syphic
    Rick if you know the prices of the ticket then here is a simple script.
    This script is just and example and is not for production use.
    This is the longer, hardcoded away of doing it but it could be done by database which would be easier to maintain and change prices like spryandrew explained.

    Thank you and have a good day

    Code:
    <?php
    
    $get_to = $_POST['to'];
    $get_from = $_POST['from'];
    $get_ppl = $_POST['ppl'];
    
    if(isset($get_to) && isset($get_from) && isset($get_ppl)){
    if($get_to == 'london' && $get_from='leads'){
    $price = $get_ppl * 200;
    echo 'Cost is: '.$price.'<br />';
    }
    }
    
    ?>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    To:<select name="to">
    <option value="london">London</option>
    </select>
    From: <select name="from">
    <option value="leads">Leads</option>
    </select>
    People: <input type="text" name="ppl" />
    <input type="submit" value="Submit" />
    </form>
    That works but takes allot of editing if you are going to use more destinations.

  8. #8
    To be honest i cant be botherd messing about withdata base's id rather have it in a script and edited the scripts

  9. #9
    Join Date
    Oct 2004
    Location
    UK
    Posts
    487
    If your going to avoid using a database, your going to be best off using Arrays to store the locations, rather than using hundreds/thousands of boolean statements.

    Look into using dual arrays to store the 2 locations and the price for the 2.

    The other option is flat file databasing, avoiding using MySQL.

  10. #10
    Join Date
    Jul 2003
    Location
    Goleta, CA
    Posts
    5,550
    I strongly urge you to go the database route. What happens when the travel agency wants you to sort trips by popularity. Maybe they want added information like which trips have a lot of viewers but no buyers. This seems like it would be much easier to expand using a database system. maybe the price is too high etc. Find ways to make more money whenever you can.
    Patron: I'd like my free lunch please.
    Cafe Manager: Free lunch? Did you read the fine print stating it was an April Fool's joke.
    Patron: I read the same way I listen, I ignore the parts I don't agree with. I'm suing you for false advertising.
    Cafe Owner: Is our lawyer still working pro bono?

  11. #11
    Join Date
    Jan 2003
    Location
    USA, FL
    Posts
    251
    As I stated within my code; the easier and better way would be to do by database. The small 5 min work was a concept to give a raw/basic idea of what you were askin for and what you were wanting. Again, as I stated, it was the hardcoded way and if you know the basics this could be easily integrated into the use of a database as below. Again, this is not for production but for a basic example.

    Example and this is only the PHP part.

    [code]
    Code:
    $get_to = $_POST['to'];
    $get_from = $_POST['from'];
    $get_ppl = $_POST['ppl'];
    
    // table structure - flight table : Fields (flight_id, flight_to, flight_from, flight_price)
    
    $result = mysql_query("SELECT * FROM flight_table WHERE flight_to='$get_to' && '$get_from' ");
    $flight = mysql_fetch_assoc($result);
    
    if(isset($get_to) && isset($get_from) && isset($get_ppl)){
    if($get_to == 'london' && $get_from='leads'){
    $price = $get_ppl * $flight['flight_price'];
    echo 'Cost is: '.$price.'<br />';
    }
    }
    This code atleast needs some some sql injection and validation of variables. I would also suggest a more optmized approach for the database. Something like:

    table: location_to
    location_to_id
    location_to_name

    table: location_from
    location_from_id
    location_from_name

    table: flight_price
    flight_id
    flight_to
    flight_from
    flight_price

    Again this is just one of the many ways of doing it. It hightly depends on how complex and detailed it needs to be.

Posting Permissions

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