標題:
第108題詳解
[打印本頁]
作者:
admin
時間:
2010-2-11 20:44
標題:
第108題詳解
PHA01-1.php
<html>
<head>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>3個數字的運算式</title>
</head>
<body>
<p align="center"><h2>3個數字的運算式</h2></p>
<form action="PHA01-2.php" method="post">
<p>請輸入第1個數字:<input type="text" name="T1" size="10"></p>
<p>請輸入第2個數字:<input type="text" name="T2" size="10"></p>
<p>請輸入第3個數字:<input type="text" name="T3" size="10"></p>
<p><input type="checkbox" name="C1" value="ON">三數相加
<input type="checkbox" name="C2" value="ON">三數相減
<input type="checkbox" name="C3" value="ON">三數相乘
<input type="checkbox" name="C4" value="ON">三數相除</p>
<p><input type="submit" value="送出" name="B1"> <input type="reset" value="重新設定" name="B2"></p>
</form>
</body>
</html>
複製代碼
PHA01-2.php
<?
$n[] = 3;
$n[0] = $_POST["T1"];
$n[1] = $_POST["T2"];
$n[2] = $_POST["T3"];
$c1 = $_POST["C1"];
$c2 = $_POST["C2"];
$c3 = $_POST["C3"];
$c4 = $_POST["C4"];
if(($n[0] == null) || ($n[1] == null) ||($n[2] == null)){
header("Location:PHA01-3.php?n1=".$n[0]."&n2=".$n[1]."&n3=".$n[2]);
//header("Location:PHA01-3.php?n1={$n1}&n2={$n2}&n3={$n3}");
}
$max = 0;
for($i=0; $i<3; $i++){
if($max < $n[$i]){
$max = $n[$i];
}
}
echo "<h2>最大數為:".$max;
$min = $n[0];
for($i=0; $i<3; $i++){
if($min > $n[$i]){
$min = $n[$i];
}
}
echo "<h2>最小數為:".$min."<br>";
if($c1 == "ON"){
echo "三數相加為:".($n[0]+$n[1]+$n[2])."<br>";
}
if($c2 == "ON"){
echo "三數相減為:".($n[0]-$n[1]-$n[2])."<br>";
}
if($c3 == "ON"){
echo "三數相乘為:".($n[0]*$n[1]*$n[2])."<br>";
}
if($c4 == "ON"){
echo "三數相除為:".($n[0]/$n[1]/$n[2])."<br>";
}
?>
複製代碼
PHA01-3.php
<html>
<body>
<?
$x1 = $_GET["n1"];
$x2 = $_GET["n2"];
$x3 = $_GET["n3"];
$xx = "第";
if($x1 == null){
$xx = $xx."一 ";
}
if($x2 == null){
$xx = $xx."二 ";
}
if($x3 == null){
$xx = $xx."三 ";
}
$xx = $xx."個文字方塊必須輸入數字";
echo "<h2>".$xx."</h2><br>";
?>
<form action="PHA01-1.php" method="post">
<input type="submit" value="回上一頁">
</form>
</body>
</html>
複製代碼
作者:
tony
時間:
2010-2-19 19:52
[attach]3[/attach]
2010/2/19 test
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2