这是为了向特定教师的学生展示。现在让您了解更多信息,请阅读以下声明:
我首先为所有课程创建了一个循环语句。然后,每个循环,我还插入另一个循环语句,让主题按程序显示特定教师和小组的每门课程的科目。然后我又提出了另一个循环语句来向学生展示每门课程。我已成功展示了学生,但问题是我不能算上所有学生。任何人?请帮我。顺便说一句,这是我的代码。
/* Get the Total Students */
$get_courses = $db_con->prepare("SELECT * FROM courses");
$get_courses->execute();
while ($course = $get_courses->fetch(PDO::FETCH_ASSOC)) {
$get_subjs = $db_con->prepare("SELECT * FROM subjects WHERE course = :course AND f_id = :f_id GROUP BY COURSE");
$get_subjs->bindparam(":course", $course["course_acronym"]);
$get_subjs->bindparam(':f_id', $my_fac_id);
$get_subjs->execute();
while ($subjects = $get_subjs->fetch(PDO::FETCH_ASSOC)) {
$get_stds = $db_con->prepare("SELECT * FROM students WHERE course = :course");
$get_stds->bindparam(":course", $course['course_acronym']);
$get_stds->execute();
while ($stds = $get_stds->fetch(PDO::FETCH_ASSOC)) {
echo $stds["firstname"] . ' ' . $stds["lastname"] . "<br/>";
}
}
}
非常感谢您的帮助。
答案 0 :(得分:0)
在每个课程循环的学生中,您可以将当前学生分配到数组变量并通过计算得到学生总数:
/* Get the Total Students */
$get_courses = $db_con->prepare("SELECT * FROM courses");
$get_courses->execute();
while ($course = $get_courses->fetch(PDO::FETCH_ASSOC)) {
$get_subjs = $db_con->prepare("SELECT * FROM subjects WHERE course = :course AND f_id = :f_id GROUP BY COURSE");
$get_subjs->bindparam(":course", $course["course_acronym"]);
$get_subjs->bindparam(':f_id', $my_fac_id);
$get_subjs->execute();
while ($subjects = $get_subjs->fetch(PDO::FETCH_ASSOC)) {
$get_stds = $db_con->prepare("SELECT * FROM students WHERE course = :course");
$get_stds->bindparam(":course", $course['course_acronym']);
$get_stds->execute();
while ($stds = $get_stds->fetch(PDO::FETCH_ASSOC)) {
echo $stds["firstname"] . ' ' . $stds["lastname"] . "<br/>";
$students[$stds["firstname"] . $stds["lastname"]] = '1';
}
}
}
$total_students = isset($students) ? count($students) : '0';