基于PHP和MYSQL做一个班级学生成绩管理系统,里面需要包含以下几点:1、学生表(学号、姓名、性别、年龄、身份证号、专业编号、班级编号、联系方式、家庭住址、备注) 2、课程表(课程编号、课程名称、主编、出版社、学分) 3、选课表(学号、课程编号、分数)4、学生选课界面 5、成绩查询界面,能够通过网页实现班级指定课程所有同学的成绩,能够实现指定学生所有课程的成绩,能够实现指定课程、指定学生的成绩,要求查询信息完整 6、补考查询界面,能够通过网页实现指定班级、指定课程的补考名单,能够实现指定学生补考名单.并给出以上进程相应的代码.
时间: 2023-09-17 13:12:08 浏览: 83
以下是一个简单的实现代码,仅供参考:
1. 学生表的建立
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sno` varchar(20) NOT NULL,
`name` varchar(20) NOT NULL,
`sex` varchar(10) NOT NULL,
`age` int(11) NOT NULL,
`idcard` varchar(20) NOT NULL,
`major_id` int(11) NOT NULL,
`class_id` int(11) NOT NULL,
`contact` varchar(50) NOT NULL,
`address` varchar(100) NOT NULL,
`remark` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `sno` (`sno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2. 课程表的建立
CREATE TABLE `course` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cno` varchar(20) NOT NULL,
`name` varchar(50) NOT NULL,
`editor` varchar(50) NOT NULL,
`publisher` varchar(50) NOT NULL,
`credit` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `cno` (`cno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3. 选课表的建立
CREATE TABLE `score` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sno` varchar(20) NOT NULL,
`cno` varchar(20) NOT NULL,
`score` float NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `sno_cno` (`sno`,`cno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4. 学生选课界面的实现
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "root", "password", "database_name");
// 检查连接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// 查询可选课程
$sql = "SELECT * FROM course";
$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["cno"]."</td>";
echo "<td>".$row["name"]."</td>";
echo "<td>".$row["editor"]."</td>";
echo "<td>".$row["publisher"]."</td>";
echo "<td>".$row["credit"]."</td>";
echo "<td><a href='add_score.php?cno=".$row["cno"]."'>选课</a></td>";
echo "</tr>";
}
echo "</table>";
// 关闭连接
mysqli_close($conn);
?>
5. 成绩查询界面的实现
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "root", "password", "database_name");
// 检查连接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// 查询班级指定课程所有同学的成绩
$sql = "SELECT student.name, score.score FROM student, score WHERE student.sno=score.sno AND student.class_id='class_id' AND score.cno='cno'";
$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["name"]."</td>";
echo "<td>".$row["score"]."</td>";
echo "</tr>";
}
echo "</table>";
// 查询指定学生所有课程的成绩
$sql = "SELECT course.name, score.score FROM course, score WHERE course.cno=score.cno AND score.sno='sno'";
$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["name"]."</td>";
echo "<td>".$row["score"]."</td>";
echo "</tr>";
}
echo "</table>";
// 查询指定课程、指定学生的成绩
$sql = "SELECT score.score FROM score WHERE score.sno='sno' AND score.cno='cno'";
$result = mysqli_query($conn, $sql);
// 输出查询结果
while ($row = mysqli_fetch_assoc($result)) {
echo "成绩:".$row["score"];
}
// 关闭连接
mysqli_close($conn);
?>
6. 补考查询界面的实现
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "root", "password", "database_name");
// 检查连接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// 查询指定班级、指定课程的补考名单
$sql = "SELECT student.name FROM student, score WHERE student.sno=score.sno AND student.class_id='class_id' AND score.cno='cno' AND score.score<60";
$result = mysqli_query($conn, $sql);
// 输出查询结果
echo "<table>";
echo "<tr><th>姓名</th></tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row["name"]."</td>";
echo "</tr>";
}
echo "</table>";
// 查询指定学生补考名单
$sql = "SELECT course.name FROM course, score WHERE course.cno=score.cno AND score.sno='sno' AND score.score<60";
$result = mysqli_query($conn, $sql);
// 输出查询结果
echo "<table>";
echo "<tr><th>课程名称</th></tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row["name"]."</td>";
echo "</tr>";
}
echo "</table>";
// 关闭连接
mysqli_close($conn);
?>
阅读全文