<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- 传递的两种方式
1.URL
2.表单
-->
<!-- 输入考号查询成绩 -->
<div>
<form action="php4.php" method="post">
考号: <input type="text" name="code">
<br />
<input type="submit" value='查询'>
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>成绩</title>
</head>
<body>
<h1>欢迎</h1>
<?php
$arr = array();
$arr['123'] = array('username' => '张三', 'math' => '140', 'english' => '60', 'chinese' => '80');
$arr['124'] = array('username' => '王五', 'math' => '40', 'english' => '40', 'chinese' => '100');
$arr['125'] = array('username' => '赵六', 'math' => '140', 'english' => '120', 'chinese' => '110');
$code = $_POST['code'];
if($code == 'admin') {
foreach ($arr as $value) {
echo "
<ul>
<li>姓名:$value[username]</li>
<li>数学:$value[math]</li>
<li>英语:$value[english]</li>
<li>语文:$value[chinese]</li>
</ul>
";
}
}else {
$score = $arr[$code];
echo "
<ul>
<li>姓名:$score[username]</li>
<li>数学:$score[math]</li>
<li>英语:$score[english]</li>
<li>语文:$score[chinese]</li>
</ul>
";
}
?>
</body>
</html>