案例----查詢成績(jī)

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>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容