1. 创建phpweb数据库,数据库表websql ``sql CREATE TABLEwebsql(IDint(11) DEFAULT NULL COMMENT '自动编号',namevarchar(20) DEFAULT NULL COMMENT '个人姓名',agetinyint(4) DEFAULT NULL COMMENT '个人年龄',Result` varchar(20) DEFAULT NULL COMMENT ‘个人成绩’ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    1. 2. phpstudywww目录下新建phpweb文件夹新建conn.php数据库连接文件
    2. ```php
    3. <?php
    4. $conn = mysqli_connect("localhost", "root", "root");
    5. @mysqli_set_charset($conn, utf8);
    6. @mysql_query($conn, utf8);
    7. if (mysqli_connect_errno($conn)){
    8. echo "连接MySQL失败:".mysqli_connect_error();
    9. }
    1. 列表首页,php语法和html表格嵌套从数据库查询出数据并分页,点击详情跳转detail.php页面通过ID传递参数 ```php <?php require_once(‘conn.php’); ?>

      <?php $conn = mysqli_connect(“localhost”, “root”, “root”, “phpweb”); $sql=mysqli_query($conn,”select count(*) as total from websql”); //建立统计有计录集总数查询; $info=mysqli_fetch_array($sql); //使用mysqli_fetch_array获取所有记录集; $total=$info[‘total’]; //定义变量$total值为记录集的总数; if($total==0) { echo “本系统暂无任何查询数据!”; } //如果记录总数为0则显示无数据; else { ?>

      PHP成绩查询系统


      1. <tr>
      2. <td>序号</td>
      3. <td>姓名</td>
      4. <td>年龄</td>
      5. <td>成绩</td>
      6. <td>操作</td>
      7. </tr>
      8. <?php
      9. $pagesize=5;
      10. //设置每页显示5条记录;
      11. if ($total<=$pagesize){
      12. $pagecount=1;
      13. //定义$pagecount初使变量为1页;
      14. }
      15. if(($total%$pagesize)!=0){
      16. $pagecount=intval($total/$pagesize)+1;
      17. //取页面统计总数为整数;
      18. }else{
      19. $pagecount=$total/$pagesize;
      20. }
      21. if((@ $_GET['page'])==""){
      22. $page=1;
      23. //如果总数小于5则页码显示为1页;
      24. }else{
      25. $page=intval($_GET['page']);
      26. //如果大于5条则显示实际的总数;
      27. }
      28. $sql1=mysqli_query($conn,"select * from websql order by ID asc limit ".($page-1)*$pagesize.",$pagesize ");
          //设置websql数据表按ID升序排序查询出所有数据;
          while($info1=mysqli_fetch_array($sql1))
              //使用mysqli_fetch_array查询所有记录集,并定义为$info1;
          {
              ?>
              <tr>
                  <td><?php echo $info1['ID'];?></td><!--显示ID字段-->
                  <td><?php echo $info1['name'];?></td><!--显示name字段-->
                  <td><?php echo $info1['age'];?></td><!--显示age字段-->
                  <td><?php echo $info1['Result'];?></td><!--显示Result字段-->
                  <td><a href="detail.php?ID=<?php echo $info1['ID'];?>">详情</a></td>
                  <!--设置跳转并传递ID值-->
              </tr>
              <?php
          }
          ?>
      </table>
      
      
      
      
      
      
      
      
      <table width="600" border="1" align="center" cellpadding="1" cellspacing="1">
          <tr>
              <td>共有数据
                  <?php
                  echo $total;//显示总页数;
                  ?>
                  &nbsp;条,每页显示&nbsp;<?php echo $pagesize;//打印每页显示的总页码;?>&nbsp;条,&nbsp;第&nbsp;<?php echo $page;//显示当前页码;?>&nbsp;页/共&nbsp;<?php echo $pagecount;//打印总页码数 ?>&nbsp;页:
                  <?php
                  if($page>=2)
                      //如果页码数大于等于2则执行下面程序
                  {
                      ?>
                      <a href="index.php?page=1" title="首页"><font face="webdings"> 9 </font></a> / <a href="index.php?id=<?php echo $id;?>&amp;page=<?php echo $page-1;?>" title="前一页"><font face="webdings"> 7 </font></a>
                      <?php
                  }
                  if($pagecount<=4){
                      //如果页码数小于等于4执行下面程序
                      for($i=1;$i<=$pagecount;$i++){
                          ?>
                          <a href="index.php?page=<?php echo $i;?>"><?php echo $i;?></a>
                          <?php
                      }
                  }else{
                      for($i=1;$i<=4;$i++){
                          ?>
                          <a href="index.php?page=<?php echo $i;?>"><?php echo $i;?></a>
                      <?php }?>
                      <a href="index.php?page=<?php echo $page-1;?>" title="后一页"><font face="webdings"> 8 </font></a> <a href="index.php?id=<?php echo $id;?>&amp;page=<?php echo $pagecount;?>" title="尾页"><font face="webdings"> : </font></a>
                  <?php }?></td>
          </tr>
      </table>
      <?php
      

      }

      ?>


       

      ![image.png](https://cdn.nlark.com/yuque/0/2022/png/1590333/1657059496236-483f63b0-a561-431e-be7d-e8c3fa0f8e14.png#clientId=u8ae89247-98da-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=236&id=u093f1ba8&margin=%5Bobject%20Object%5D&name=image.png&originHeight=260&originWidth=656&originalType=binary&ratio=1&rotation=0&showTitle=false&size=18234&status=done&style=none&taskId=ud0373066-a59e-4094-b0cc-8f34dc413db&title=&width=596.363623437803)
      
      4. 列表详情页detail.php
      ```php
      <?php require_once('conn.php'); ?>
      <html>
      <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>PHP成绩查询系统</title>
          <style type="text/css">
              .aline_center {
                  text-align: center;
              }
              .ca {
                  text-align: center;
              }
          </style>
      </head>
      <body class="ca">
      <p class="aline_center">PHP成绩查询系统</p>
      <hr/>
      <table width="600" border="1" align="center" cellpadding="1" cellspacing="1">
          <tr>
              <td>序号</td>
              <td>姓名</td>
              <td>年龄</td>
              <td>成绩</td>
              <td>编辑</td>
          </tr>
          <?php
          $conn = mysqli_connect("localhost", "root", "root", "phpweb");
          $ID = @ $_GET['ID'];
          $sql = mysqli_query($conn, "select * from websql where ID = '".$ID."'");
          $info = mysqli_fetch_array($sql);
          ?>
          <tr>
              <td><?php echo $info['ID'];?></td>
              <td><?php echo $info['name'];?></td>
              <td><?php echo $info['age'];?></td>
              <td><?php echo $info['Result'];?></td>
              <td><a href="update.php?ID=<?php echo $info['ID'];?>">更新</a> / <a href="del.php?ID=<?php echo $info['ID'];?>">删除</a></td>
          </tr>
      </table>
      <hr/>
      <p>&nbsp</p>
      </body>
      </html>
      

      image.png

      1. 点击详情后点击更新根据ID值跳转update.php详情页面 ```php <?php require_once(‘conn.php’); ?>

      PHP成绩查询系统


      <?php $ID=@ $_GET[‘ID’]; $conn = mysqli_connect(“localhost”, “root”, “root”, “phpweb”); $sql=mysqli_query($conn,”select * from websql where ID=’”.$ID.”‘“); $info=mysqli_fetch_array($sql); ?>
      序号 姓名 年龄 成绩
      <?php echo $info[‘ID’];?>


       

       

      ```