dongxia2030 2011-11-20 10:17
浏览 45
已采纳

距离成本计算器

Hello I am looking for a distance cost calculator like airports, taxi firms would have for example:

from x to xx it will cost ...

here is what i have made with help from some others here: http://pastebin.com/0pSF7VsA however i cannot work out how to get it to work e.g. do the maths when the user selects it from the form.

here is my form so far: http://pastebin.com/sq14eYMQ

thanks

  • 写回答

1条回答 默认 最新

  • dongmin3754 2011-11-20 11:14
    关注

    Heres a clean up and an example of the calculations after post. hope it helps.

    <?php
    error_reporting(E_ALL);
    
    /* places array, multi dimensional could also be used but noticed prices are the same  */
    $data = array("Algeciras"=>10,"Almuñecar"=>20,"Alora"=>30,"Antequera"=>10,"Benahavis"=>15,
    "Benalmadena costa"=>20,"Benalmadena pueblo"=>25,"Calahonda"=>30,"Cartama"=>40,
    "Coin"=>12,"Estepona"=>15,"El Faro"=>20,"Frigiliana"=>16,"Fuengirola"=>30,"Gibraltar frontier - La Linea"=>12,
    "Granada"=>30,"La Cala de Mijas"=>10,"La Cala Golf Resort"=>20,"Malaga"=>5,"Manilva"=>12,"Marbella"=>20,"Mijas Costa"=>7,
    "Mijas Pueblo"=>20,"Nerja"=>10,"Puerto Banus"=>15,"Puerto de la Duquesa"=>10,"Rincon de la victoria"=>23,
    "Ronda"=>20,"San Pedro de Alcantara"=>10,"San Roque"=>20,"Sierra Nevada"=>12,"Sotogrande"=>19,"Tarifa"=>20,
    "Torre del Mar"=>30,"Torremolinos"=>10,"Torremuelle"=>14,"Torrenueva"=>18,"Torrox Costa"=>11);
    
    
    /* number of people array */
    $car=array('1'=>0,'2'=>50,'3'=>70,'4'=>90,'5+'=>110);
    
    
    $now = date("H:i");
    $cutoff = "18:56";
    
    function rateOffset($now, $cutoff){
        if ($now < strtotime($cutoff)){
            // if less than 6:56pm add 20.00 20.00 euros to price
            return 20.00;
        } else {
            // if more than 6:56pm add only 6 euros to price
            return 6.00;
        }
    }
    
    //This is a basic example of how to check if the form was posted
    if(isset($_POST['name']) && isset($_POST['to'])){
    
        if(isset($_POST['from']) && $_POST['from']=='Gibraltar'){
            /* places array to overwrite malaga prices   */
            $data = array("Algeciras"=>10,"Almuñecar"=>20,"Alora"=>30,"Antequera"=>10,"Benahavis"=>15,
            "Benalmadena costa"=>20,"Benalmadena pueblo"=>25,"Calahonda"=>30,"Cartama"=>40,
            "Coin"=>12,"Estepona"=>15,"El Faro"=>20,"Frigiliana"=>16,"Fuengirola"=>30,"Gibraltar frontier - La Linea"=>12,
            "Granada"=>30,"La Cala de Mijas"=>10,"La Cala Golf Resort"=>20,"Malaga"=>5,"Manilva"=>12,"Marbella"=>20,"Mijas Costa"=>7,
            "Mijas Pueblo"=>20,"Nerja"=>10,"Puerto Banus"=>15,"Puerto de la Duquesa"=>10,"Rincon de la victoria"=>23,
            "Ronda"=>20,"San Pedro de Alcantara"=>10,"San Roque"=>20,"Sierra Nevada"=>12,"Sotogrande"=>19,"Tarifa"=>20,
            "Torre del Mar"=>30,"Torremolinos"=>10,"Torremuelle"=>14,"Torrenueva"=>18,"Torrox Costa"=>11);
        }
    
        $rateCalc = rateOffset($now, $cutoff);
    
        echo $now." = $rateCalc<br />";
        echo "Price to {$_POST['to']} from {$_POST['from']}: ".number_format($data[$_POST['to']],2)."<br />";
        echo "Number of people price: ".number_format($car[$_POST['people']],2)."<br />";
        echo "Time rate calculator: ".$rateCalc."<br /><hr />";
    
        $total = number_format($data[$_POST['to']],2) + number_format($car[$_POST['people']],2) + $rateCalc." in euros<br /><br />";
        echo "Total: ".$total;
    
    }else{
        echo '<form method="POST" action="">
                        <label>Name:</label>
                        <input type="text" value="name" name="name" />
    
                        <label>From:</label>
                        <select name="from">
                            <option selected="selected">Malaga</option>
                            <option>Gibraltar</option>
                        </select>
                        <div class="clr"></div>
    
                        <label>To:</label>
                        <select name="to">
                 ';
        foreach ($data as $place => $price){
            echo "<option>{$place}</option>
    ";
        }
        echo '</select>
                        <div class="clr"></div>
    
                        <label>Date:</label>
                        <input type="text" value="dd/mm/yyyy" id="date" name="date" />
    
                        <label>Number of people:</label>
                        <select id="people" name="people">
                            <option>1</option>
                            <option>2</option>
                            <option>3</option>
                            <option>4</option>
                            <option>5+</option>
                        </select>
                        <div class="clr"></div>
    
                        <div id="return">
                            <label>Is this a return<br />journey?</label><div class="clr"></div>
                            <div id="radio-buttons"><input type="radio" name="return" value="Yes" class="radio" />Yes<br />
                            <input type="radio" name="return" value="No" class="radio" />No</div>
                        </div>
                        <div class="clr"></div>
    
                        <input type="submit" name="submit" class="fauxButton" />
                    </form>';
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器