HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
<form action="./page6-data.php" method="POST">
學(xué)號(hào): <input type="text" name="code"><br>
<input type="submit" value="查詢">
</form>
</div>
</body>
</html>
PHP
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
<?php
$code = $_POST['code'];
// $arr 所有的學(xué)號(hào)
$arr = array();
$arr['123'] = array("username" => "張三", "chinaese" => "140", "math" => "149", "english" => "120");
$arr['124'] = array("username" => "李四", "chinaese" => "40", "math" => "142", "english" => "10");
$arr['125'] = array("username" => "王五", "chinaese" => "120", "math" => "12", "english" => "20");
$arr['126'] = array("username" => "趙六", "chinaese" => "110", "math" => "119", "english" => "50");
// 如果是管理員割笙,則遍歷所有成績(jī)
if ($code == 'admin') {
foreach ($arr as $key => $value) {
echo "<ul>
<li>姓名:$value[username]</li>
<li>語(yǔ)文:$value[chinaese]</li>
<li>數(shù)學(xué):$value[math]</li>
<li>英語(yǔ):$value[english]</li>
</ul>";
}
} else {
// 所輸入學(xué)號(hào)的成績(jī)
$score = $arr[$code];
echo "<ul>
<li>姓名:$score[username]</li>
<li>語(yǔ)文:$score[chinaese]</li>
<li>數(shù)學(xué):$score[math]</li>
<li>英語(yǔ):$score[english]</li>
</ul>";
}
?>
</div>
</body>
</html>