帮我用php建一个班级学生成绩管理系统包含学生表课程表选课表的基础界面成绩查询界面
时间: 2023-12-18 08:02:45 浏览: 90
好的,我可以为你提供一个使用PHP语言编写的班级学生成绩管理系统的示例代码,包括学生表、课程表、选课表和成绩表的基础界面和成绩查询界面。注意,这只是一个示例代码,你需要根据自己的实际需求进行修改和完善。
1. 学生表(student.php)
```
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "root", "", "school");
// 查询学生信息
$sql = "SELECT * FROM student";
$result = mysqli_query($conn, $sql);
// 输出学生信息
echo "<table>";
echo "<tr><th>学生编号</th><th>姓名</th><th>性别</th><th>年龄</th><th>年级</th><th>班级</th></tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['student_id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['gender']."</td>";
echo "<td>".$row['age']."</td>";
echo "<td>".$row['grade']."</td>";
echo "<td>".$row['class']."</td>";
echo "</tr>";
}
echo "</table>";
// 关闭连接
mysqli_close($conn);
?>
```
2. 课程表(course.php)
```
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "root", "", "school");
// 查询课程信息
$sql = "SELECT * FROM course";
$result = mysqli_query($conn, $sql);
// 输出课程信息
echo "<table>";
echo "<tr><th>课程编号</th><th>课程名称</th><th>学分</th></tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['course_id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['credit']."</td>";
echo "</tr>";
}
echo "</table>";
// 关闭连接
mysqli_close($conn);
?>
```
3. 选课表(selection.php)
```
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "root", "", "school");
// 查询选课信息
$sql = "SELECT s.name AS student_name, c.name AS course_name FROM course_selection cs JOIN student s ON cs.student_id = s.student_id JOIN course c ON cs.course_id = c.course_id";
$result = mysqli_query($conn, $sql);
// 输出选课信息
echo "<table>";
echo "<tr><th>学生姓名</th><th>课程名称</th></tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['student_name']."</td>";
echo "<td>".$row['course_name']."</td>";
echo "</tr>";
}
echo "</table>";
// 关闭连接
mysqli_close($conn);
?>
```
4. 成绩表(score.php)
```
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "root", "", "school");
// 查询成绩信息
$sql = "SELECT s.name AS student_name, c.name AS course_name, sc.score FROM score sc JOIN student s ON sc.student_id = s.student_id JOIN course c ON sc.course_id = c.course_id";
$result = mysqli_query($conn, $sql);
// 输出成绩信息
echo "<table>";
echo "<tr><th>学生姓名</th><th>课程名称</th><th>成绩</th></tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['student_name']."</td>";
echo "<td>".$row['course_name']."</td>";
echo "<td>".$row['score']."</td>";
echo "</tr>";
}
echo "</table>";
// 关闭连接
mysqli_close($conn);
?>
```
5. 成绩查询界面(query.php)
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>成绩查询</title>
</head>
<body>
<h1>成绩查询</h1>
<form method="get" action="query.php">
<label>学生编号:</label>
<input type="text" name="student_id">
<input type="submit" value="查询">
</form>
<?php
// 如果学生编号不为空,则进行成绩查询
if(!empty($_GET['student_id'])) {
$student_id = $_GET['student_id'];
// 连接数据库
$conn = mysqli_connect("localhost", "root", "", "school");
// 查询该学生所选的所有课程及成绩
$sql = "SELECT c.name AS course_name, sc.score FROM score sc JOIN course c ON sc.course_id = c.course_id WHERE sc.student_id = '$student_id'";
$result = mysqli_query($conn, $sql);
// 输出查询结果
echo "<h2>学生编号为 $student_id 的成绩如下:</h2>";
echo "<table>";
echo "<tr><th>课程名称</th><th>成绩</th></tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['course_name']."</td>";
echo "<td>".$row['score']."</td>";
echo "</tr>";
}
echo "</table>";
// 关闭连接
mysqli_close($conn);
}
?>
</body>
</html>
```
以上是一个使用PHP语言编写的班级学生成绩管理系统的示例代码,你可以根据自己的实际需求进行修改和完善。
阅读全文