制御構造ループ 5−1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja"><head>
<meta http-equiv="Content-type" content="text/html; charset=EUC-JP">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="./style.css">
<title>いくつでもどうぞ</title></head>
<body><div class="file2">
<form action="05_01_loop.php" method="post">
お好きなものを何個でもどうぞ<br />
<input type="radio" name="order" value="pizza" />ピザ
<input type="radio" name="order" value="barger" />ハンバーガー
<input type="radio" name="order" value="hotdog" />ホットドッグ
<input type="text" name="num" size="10">
<input type="submit" value="注文!"></form>
<!--ここからPHPの始まりです。//-->
<?php
error_reporting(1);
$order = $_POST['order'];
$num = $_POST['num'];
$num = htmlspecialchars($num, ENT_QUOTES); /*タグを無効化 */
if($order == "pizza") {
$pict = "<img src='img/pizza.gif'>";
} else if ($order == "barger") {
$pict = "<img src='img/humbarger.gif'>";
} else if ($order == "hotdog") {
$pict = "<img src='img/hotdog.gif'>";
} else {
}
if($num >=1 and $num <= 100){
echo "どうぞ!!<br />";
$a = 0;
while($a < $num) {
echo $pict;
$a++;
}
} else if ($num > 100) {
echo "やっぱりだめ!$num 個なんて多すぎ!1個だけあげる。<br />";
echo $pict;
} else {
}
?> <!--これでPHPは終わりです。//-->
</div></body></html>