情報処理実習3B(Web)

2017年度 前期 木04 15:15-16:45 瀬田2-119

課題

05.array/distance.php

表示
ソース

<?php
//梅田からの営業キロ
$stations = array(
'梅田'       => 0,
'十三'       => 2.4,
'南方'       => 4.3,
'崇禅寺'     => 5.6,
'淡路'       => 6.6,
'上新庄'     => 8.7,
'相川'       => 9.6,
'正雀'       =>11.8,
'摂津市'     =>13.3,
'南茨木'     =>15.3,
'茨木市'     =>17.2,
'総持寺'     =>18.6,
'富田'       =>19.7,
'高槻市'     =>23.0,
'上牧'       =>27.3,
'水無瀬'     =>28.1,
'大山崎'     =>30.1,
'西山天王山' =>32.6,
'長岡天神'   =>34.1,
'西向日'     =>36.0,
'東向日'     =>37.4,
'洛西口'     =>38.7,
'桂'         =>40.4,
'西京極'     =>42.5,
'西院'       =>44.3,
'大宮'       =>45.7,
'烏丸'       =>48.6,
'河原町'     =>47.7
);

//フォームからの変数の受け取り
if($_GET['submit']){
    $start = $_GET['start'];
    $end = $_GET['end'];
}

//営業キロ計算
$distance = $end - $start;
if($distance < 0){
    $distance = -$distance;
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
   <meta charset="UTF-8" />
   <meta name="viewport" content="initial-scale=1.0">
   <link rel="stylesheet" href="" />
   <title>阪急京都線駅間距離</title>
</head>
<body>
<h1>阪急京都線駅間距離</h1>
<form action="" method="GET">
<fieldset style="width:10em;box-shadow:0.1em 0.2em 0.2em 0.1em #c0c0c0">
<legend>発着駅</legend>
出発:<select name="start">
<?php
//発駅をフォームとして出力☆
foreach($stations as $station => $value){
?>
<option value="<?php print $value ;?>" <?php if($station == $start) print 'selected';?>><?php print $stations;?></option>
<?php
}
?>
</select><br>
到着:<select name="end">
<?php
//着駅をフォームとして出力☆
foreach($stations as $station => $value){
?>
<option value="<?php print $station ;?>" <?php if($station == $end) print 'selected';?>><?php print $value;?></option>
<?php
}
?>
</select>
</fieldset>
<p><button type="submit" name="submit" value="culc">計算する</button><button type="submit" name="reset" value="reset">リセット</button></p>
</form>
<?php
if($_GET['submit']){
?>
<div class="result" style="width:15em;padding:0.1em 1em;box-shadow:0.1em 0.2em 0.2em 0.1em #c0c0c0">
<p>距離:<?php print $distance ;?>営業キロ</p>
</div>
<?php
}
?>
</body>
</html>