我目前在 MySQL 数据库中有 5 个表。其中一些共享外键并且相互依赖。我根据他们的专业显示课程。每节课都在或fall
期间教授。在我的数据库中,我有一个名为 term 的表,其中包含、和字段。特别是该字段是具有三个值的 a ,,。这表示,或。当我显示查询而不是显示查询时,或者我可以显示查询等 ?额外:如何在每个循环的末尾添加空间,使数据看起来不聚集?spring
all_year
id
year
semester
semester
tinyint
0
1
2
fall
spring
all_year
0
1
2
fall
spring
钥匙
0 Fall
1 Spring
2 All-year
PHP
<?
try {
$pdo = new PDO ("mysql:host=$hostname;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
$query = $pdo->prepare("SELECT course.name, course.code, course.description, course.hours, semester.semester, semester.year
FROM course
LEFT JOIN major_course_xref ON course.id = major_course_xref.course_id
LEFT JOIN major ON major.id = major_course_xref.major_id
LEFT JOIN course_semester_xref ON course.id = course_semester_xref.course_id
LEFT JOIN semester ON course_semester_xref.semester_id = semester.id");
$query->execute();
if ($query->execute()){
while ($row = $query->fetch(PDO::FETCH_ASSOC)){
print $row['name'] . "<br>";
print $row['code'] . "<br>";
print $row['description'] . "<br>";
print $row['hours'] . " hrs.<br>";
print $row['semester'] . "<br>";
print $row['year'] . "<br>";
}
}
else
echo 'Could not fetch results.';
unset($pdo);
unset($query);
?>
当前显示
Computer Programming I
CPSC1400
Introduction to disciplined, object-oriented program development.
4 hrs.
0
2013
欲望展示
Computer Programming I
CPSC1400
Introduction to disciplined, object-oriented program development.
4 hrs.
Fall
2013