1. 连接数据库:使用PHP中的mysqli_connect函数连接数据库,需要提供主机名、用户名、密码和数据库名等参数。
  2. 查询数据:使用SQL语句从student表中查询所有记录,例如:SELECT * FROM stuinfo。
  3. 遍历结果集:使用mysqli_fetch_assoc函数遍历查询结果集,将每条记录存储在关联数组中。
  4. 输出到网页:使用HTML标签和PHP语句将记录输出到网页中,例如:
<table>
  <tr>
    <th>学号</th>
    <th>姓名</th>
    <th>年龄</th>
    <th>成绩</th>
    <th>地址</th>
  </tr>
  <?php
    while($row = mysqli_fetch_assoc($result)) {
      echo '<tr>';
      echo '<td>'.$row['xuehao'].'</td>';
      echo '<td>'.$row['name'].'</td>';
      echo '<td>'.$row['age'].'</td>';
      echo '<td>'.$row['score'].'</td>';
      echo '<td>'.$row['address'].'</td>';
      echo '</tr>';
    }
  ?>
</table>

其中$result为查询结果集。


原文地址: https://www.cveoy.top/t/topic/fZYD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录