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é)號: <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é)號
$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");
// 如果是管理員,則遍歷所有成績
if ($code == 'admin') {
foreach ($arr as $key => $value) {
echo "<ul>
<li>姓名:$value[username]</li>
<li>語文:$value[chinaese]</li>
<li>數(shù)學(xué):$value[math]</li>
<li>英語:$value[english]</li>
</ul>";
}
} else {
// 所輸入學(xué)號的成績
$score = $arr[$code];
echo "<ul>
<li>姓名:$score[username]</li>
<li>語文:$score[chinaese]</li>
<li>數(shù)學(xué):$score[math]</li>
<li>英語:$score[english]</li>
</ul>";
}
?>
</div>
</body>
</html>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。