本人是一位学生,正在学习当中,可能BUG众多,请见谅并指正,谢谢!!!
学生列表实现
HTML:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>学生信息</title> <link rel="stylesheet" type="text/css" href="css/Bootstrap.css"> </head> <body> <div class="container mt-5"> <h1 class="display-4 text-center">学生信息管理中心</h1> <div class="row mt-3"> <a class="btn btn-info col-sm-2" style="margin-right: 88px; margin-left: 15px;" href="add_student.php">添加学生</a> <input type="text" class="form-control col-sm-6 ml-5" placeholder="请输入关键词"> <button type="submit" class="btn btn-info col-sm-2 ml-4">点击搜索</button> </div> <table class="table table-hover table-bordered mt-3"> <thead class="thead-inverse"> <tr> <th class="text-center align-middle">学号</th> <th class="text-center align-middle">学院/系</th> <th class="text-center align-middle">班级</th> <th class="text-center align-middle">姓名</th> <th class="text-center align-middle">性别</th> <th class="text-center align-middle">年龄</th> <th class="text-center align-middle">照片</th> <th class="text-center align-middle">操作</th> </tr> </thead> <tbody class="text-center"> <?php while ($student = mysqli_fetch_assoc($query)): ?> <tr> <td class="align-middle"><?php echo $student['num']; ?></td> <td class="align-middle"><?php echo $student['system']; ?></td> <td class="align-middle"><?php echo $student['class']; ?></td> <td class="align-middle"><?php echo $student['name']; ?></td> <td class="align-middle"><?php echo $student['gender'] === 1 ? '♂' : '♀'; ?></td> <td class="align-middle"><?php echo date('Y') - substr($student['birthday'], 0, 4); ?></td> <td class="align-middle"><img src="<?php echo $student['photo']; ?>" width="100" height="70"></td> <td class="align-middle"><a class="btn btn-info mr-2" href="edit.php?num=<?php echo $student['num']; ?>">编辑</a><a class="btn btn-danger ml-2" href="delete.php?num=<?php echo $student['num']; ?>">删除</a></td> </tr> <?php endwhile ?> </tbody> </table> </div> </body> </html>
PHP:
// 这里:
// 第一个参数:本地网络地址
// 第二个参数:数据库账号
// 第三个参数:数据库密码
// 第四个参数:数据库名称
$connection = mysqli_connect('localhost', 'root', '密码', 'students_info_system'); if (!$connection) { exit('<h1>连接数据库失败</h1>'); } $query = mysqli_query($connection, 'selec