创建两个页面,score.html作为查询页面,result.php作为结果输出页面。
当用户输入正确的考号,跳转result页面并输出各学科成绩。如果考号错误则提示“抱歉!您输入的考号不存在。”
score.gif
代码如下:

score.html—查询页

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>学生成绩查询</title>
  6. <link rel="stylesheet" href="css/score.css">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <h3>学生成绩查询</h3>
  11. <form action="result.php" method="get">
  12. <input placeholder="请输入您的学号" name="codeNum" class="num">
  13. <input type="submit" value="查询" class="subBtn">
  14. </form>
  15. </div>
  16. </body>
  17. </html>

result.php—结果页

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  6. <title>结果查询</title>
  7. <link rel="stylesheet" href="css/score.css">
  8. </head>
  9. <body>
  10. <?php
  11. $data = array();
  12. $data['123'] = array('name'=>'张三','chinese'=>'120','math'=>'98','english'=>'101','history'=>'88','geography'=>'93');
  13. $data['321'] = array('name'=>'李四','chinese'=>'110','math'=>'89','english'=>'42','history'=>'113','geography'=>'70');
  14. $data['456'] = array('name'=>'王五','chinese'=>'90','math'=>'120','english'=>'76','history'=>'85','geography'=>'88');
  15. $codeNum = $_GET['codeNum'];
  16. ?>
  17. <?php
  18. //判断数组中是否包含索引号
  19. if(array_key_exists($codeNum,$data)){
  20. $result = $data[$codeNum];
  21. ?>
  22. <div class="container resBox">
  23. <h3><span><?php echo $result['name'] ?></span>个人成绩:</h3>
  24. <table class="scoreList">
  25. <thead>
  26. <tr>
  27. <th>语文</th>
  28. <th>数学</th>
  29. <th>英语</th>
  30. <th>历史</th>
  31. <th>地理</th>
  32. </tr>
  33. </thead>
  34. <tbody>
  35. <tr>
  36. <td><?php echo $result['chinese'] ?></td>
  37. <td><?php echo $result['math'] ?></td>
  38. <td><?php echo $result['english'] ?></td>
  39. <td><?php echo $result['history'] ?></td>
  40. <td><?php echo $result['geography'] ?></td>
  41. </tr>
  42. </tbody>
  43. </table>
  44. </div>
  45. <?php
  46. }else{
  47. ?>
  48. <div class="msg">抱歉!您输入的考号不存在。</div>
  49. <?php
  50. }
  51. ?>
  52. </body>
  53. </html>

CSS样式

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. input{
  7. display: block;
  8. outline: none;
  9. }
  10. .container{
  11. width: 260px;
  12. margin: 20px auto;
  13. }
  14. .resBox{
  15. width: 360px;
  16. margin: 20px auto;
  17. }
  18. .container h3{
  19. font-size: 18px;
  20. text-align: center;
  21. color: #555;
  22. }
  23. .container input{
  24. width: 100%;
  25. height: 30px;
  26. }
  27. .container .num{
  28. border: 1px solid #ccc;
  29. padding-left: 5px;
  30. font-size: 15px;
  31. margin: 15px 0;
  32. }
  33. .container .num::-webkit-input-placeholder{
  34. color: #ccc;
  35. }
  36. .container .subBtn{
  37. background: steelblue;
  38. border: none;
  39. border-radius: 2px;
  40. color: #fff;
  41. font-size: 15px;
  42. }
  43. .container span{
  44. color: steelblue;
  45. }
  46. .scoreList{
  47. width: 100%;
  48. border-collapse: collapse;
  49. margin: 15px auto;
  50. }
  51. .scoreList thead{
  52. background: #eee;
  53. }
  54. .scoreList th,td{
  55. height: 36px;
  56. border: 1px solid #ccc;
  57. text-align: center;
  58. line-height: 36px;
  59. font-size: 15px;
  60. color: #555;
  61. }
  62. .msg{
  63. text-align: center;
  64. margin: 20px auto;
  65. font-size: 16px;
  66. color: #555;
  67. }