我有三个链接在一起的表。我想做的是为一个班级的所有学生生成一张成绩单。
表学生信息
name sex age students_ID
--------- --- --- -----------
Kinsley M 12 1
Michael m 12 2
Rhianna f 22 3
表score_panel
1stCA 2ndCA exam students_ID subjectID
----- ----- ---- ----------- ---------
23 15 42 1 1
10 12 7 1 2
43 15 62 1 3
10 12 27 2 1
10 12 57 2 2
23 15 12 2 3
11 12 27 3 1
04 12 57 3 2
13 25 12 3 3
表主题
subjectname subjectID
----------- ---------
english 1
maths 2
biology 3
我希望我的结果看起来像这样:
NAME KINSLEY
SEX M
AGE 12
和成绩单跟随
subject 1stCA 2ndCA EXAM
--------- ----- ----- ----
english 23 15 42
maths 10 12 7
Biology 43 15 62
...等等所有学生
只检索一门科目和分数,而不是全部
<?php
include("connect.php");
$generate="SELECT students_info.name, subject.subjectname, scores_panel.1stCA, scores_panel.2ndCA, scores_panel.EXAM
FROM
students_info
LEFT JOIN
scores_panel
ON students_info.students_ID=scores_panel.students_ID
LEFT JOIN
subject
ON
subject.subjectID=scores_panel.subjectID ";
$fetch=mysql_query($generate);
while($row=mysql_fetch_array($fetch)or die(mysql_error()))
{
?>
**NAME:**
<?PHP echo $row['name']; ?>
subject 1stCA 2ndCA EXAM
----------
<?PHP echo $row['subjectname']; ?>
<?PHP echo $row['1stCA']; ?>
<?PHP echo $row['2ndCA']; ?>
<?PHP echo $row['EXAM']; ?>
THIS IS YOUR REPORT CARD
<?PHP } ?>
它有效,但只为每个学生显示一个主题,而不是像这样:
NAME KINSLEY
SEX M
AGE 12
和成绩单跟随
subject 1stCA 2ndCA EXAM
--------- ----- ----- ----
english 23 15 42
maths 10 12 7
Biology 43 15 62
NAME Rhianna
SEX F
AGE 22
和成绩单跟随
subject 1stCA 2ndCA EXAM
--------- ----- ----- ----
english 11 12 27
maths 04 12 57
Biology 13 25 12
...等等所有学生。