<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="./css/nav.css">
<title>Document</title>
</head>
<body>
<?php include ('./nav.php'); ?>
<?php
include_once('./php/conn.php');
session_start();
$uid = $_SESSION["student_id"];
// 查询条件
$where = "";
if (isset($_POST['course_name']) && $_POST['course_name'] !== "") {
$where .= " AND course_name LIKE '%".$_POST['course_name']."%'";
}
if (isset($_POST['credit']) && $_POST['credit'] !== "") {
$where .= " AND credit = ".$_POST['credit'];
}
// 查询结果
$sql = "SELECT * FROM `course`.`course` WHERE 1=1 $where";
$result = mysqli_query($conn, $sql);
$result2 = mysqli_query($conn, "SELECT * FROM `course`.`view_course` WHERE student_id=$uid");
$courses = array();
$iscourses = array();
while ($row = mysqli_fetch_assoc($result2)) {
$iscourses[] = $row;
}
while ($row = mysqli_fetch_assoc($result)) {
$courses[] = $row;
}
// 显示课程列表
echo "<form method='post' id='form' action=''>";
echo "<label for='course_name'>课程名称:</label>";
if(isset($_POST['course_name'])){
echo "<input type='text' id='course_name' name='course_name' value='".$_POST['course_name']."'>";
}else{
echo "<input type='text' id='course_name' name='course_name' value=''>";
}
echo "<label for='credit'>学分:</label>";
if(isset($_POST['credit'])){
echo "<input type='text' id='credit' name='credit' value='".$_POST['credit']."'>";
}else{
echo "<input type='text' id='credit' name='credit' value=''>";
}
echo "<input type='submit' value='查询'>";
echo "</form>";
echo "<table>";
echo "<tr><th>编号</th><th>课程名称</th><th>学时</th><th>学分</th><th>上课时间</th><th>人数</th><th>教师名称</th><th>上课地点</th><th>操作</th></tr>";
foreach ($courses as $course) {
echo "<tr>";
echo "<td>" . $course['course_id'] . "</td>";
echo "<td>" . $course['course_name'] . "</td>";
echo "<td>" . $course['period'] . "</td>";
echo "<td>" . $course['credit'] . "</td>";
echo "<td>" . $course['attend_time'] . "</td>";
echo "<td>" . $course['capacity'] . "</td>";
echo "<td>" . $course['attend_address'] . "</td>";
echo "<td>" . $course['credit'] . "</td>";
$is=true;
foreach ($iscourses as $i) {
if($i['course_id']==$course['course_id']){
$is=false;
echo "<td><label> <a href='#'>已选择</a>";
break;
}
}
if($is){
echo "<td><label> <a href='select.php?course_id=".$course['course_id']."'>选择</a>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
<style>
table {
border-collapse: collapse;
width: 100%;
margin-bottom: 20px;
}
th,
td {
padding: 8px;
text-align: left;
border: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
color: #666;
font-weight: normal;
}
tr:hover {
background-color: #f5f5f5;
}
h1 {
margin-bottom: 20px;
text-align: center;
font-size: 28px;
}
form {
max-width: 1000px;
margin: auto;
background-color: #f2f2f2;
padding: 20px;
border-radius: 4px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
input[type="radio"] {
margin-right: 10px;
transform: scale(1.5);
-webkit-appearance: none;
appearance: none;
border-radius: 50%;
border: 1px solid #ccc;
}
input[type="button"] {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
}
input[type="button"]:hover {
background-color: #45a049;
}
</style>
</html>