好朋友。我正在使用Laravel应用程序,就像我国学校的学生管理系统一样。该申请要求我存储了数十名学生,并进一步生成学生达到该分数的期间或学期的报告。
在我的国家,通常一学年有六(6)个学期。一段时间跨越4周。一个学年还有两(2)个学期,跨越3个半月。每学期有四(4)个学期。
这是一张解释事物外观的图片:
由于我必须在给定学期的某个时期生成每个学生的报告,这就是我的概念模型的样子:
学生表:
students
--------
id *
name
grade_id (fk)
主题表:
subjects
--------
id *
name
成绩表:
grades
--------
id *
name
注意成绩表存储学校中每个班级的名称。恩。 grade 12
,grade 11
等。
现在,这些是学生在特定时期或学期的科目中得分的表格。
period_one (1st Period)
-----------------------
id *
student_id (fk)
subject_id (fk)
grade_id (fk)
score
first_exam (1st Sem. Exam)
-----------------------
id *
student_id (fk)
subject_id (fk)
grade_id (fk)
score
period_four (4th Period)
-----------------------
id *
student_id (fk)
subject_id (fk)
grade_id (fk)
score
注意同样适用于second period
,third period
,5th period
,six period
等
此时我知道有人在这里看到过腥或愚蠢的东西。我在每个表格中重复相同的列,我相信它可以做得更好。
但我有理由这样做,这与生成报告有关。通过上述设置,我可以轻松构建查询以生成报告。
这是我用来生成定期报告的查询
// the function runs a select all query for all the period/term grades tables
// It displays the periodic grades sheet
$student_id = 1; // any id could be passed
$term = "period_one"; // giving the exact table name to fetch record from
$class_id = 2; // 2 may represent grade 12 in this case.
function periodic_report($term, $student_id, $class_id)
{
global $connection;
$query = "SELECT $table.student_id, score, subject_name, class_name
from $term
INNER JOIN students
ON students.student_id = $table.student_id
INNER JOIN classes
ON classes.class_id = $table.class_id
INNER JOIN subjects
ON subjects.subject_id = $table.subject_id
WHERE $table.student_id = $student_id AND $table.class_id = $class_id";
$result_set = mysqli_query($connection, $query);
// Test if there was a query/syntax error
confirm_query($result_set);
return $result_set;
}
这是结果的样子:
查询以生成第一学期报告:
// the function runs a select all query for semester grades
// It displays the first semester grades sheet
function first_semester_report($student_id) {
global $connection;
$query = "SELECT subjects.subject_name, period_one.score, period_two.score, period_three.score, first_exam.score
FROM subjects
LEFT JOIN period_one
ON period_one.subject_id = subjects.subject_id
AND period_one.student_id = {$student_id}
LEFT JOIN period_two
ON period_two.subject_id = subjects.subject_id
AND period_two.student_id = {$student_id}
LEFT JOIN period_three
ON period_three.subject_id = subjects.subject_id
AND period_three.student_id = {$student_id}
LEFT JOIN first_exam
ON first_exam.subject_id = subjects.subject_id
AND first_exam.student_id = {$student_id}
LEFT JOIN students
ON students.student_id = {$student_id}
WHERE period_one.subject_id = subjects.subject_id OR period_two.subject_id = subjects.subject_id OR period_three.subject_id = subjects.subject_id OR first_exam.subject_id = subjects.subject_id
ORDER BY subjects.subject_name";
$result_set = mysqli_query($connection, $query);
if(!$result_set){
die("Database query failed. Error from first semester report: ".mysqli_error($connection)." Error number is: ".mysqli_errno($connection));
}
// Test if there was a query/syntax error
//confirm_query($result_set);
return $result_set;
}
查询以生成第二学期报告:
// the function runs a select all query for semester grades
// It displays the second semester grades sheet
function second_semester_report($student_id) {
global $connection;
$query = "SELECT subjects.subject_name, period_four.score, period_five.score, period_six.score, second_exam.score
FROM subjects
LEFT JOIN period_four
ON period_four.subject_id = subjects.subject_id
AND period_four.student_id = {$student_id}
LEFT JOIN period_five
ON period_five.subject_id = subjects.subject_id
AND period_five.student_id = {$student_id}
LEFT JOIN period_six
ON period_six.subject_id = subjects.subject_id
AND period_six.student_id = {$student_id}
LEFT JOIN second_exam
ON second_exam.subject_id = subjects.subject_id
AND second_exam.student_id = {$student_id}
LEFT JOIN students
ON students.student_id = {$student_id}
WHERE period_four.subject_id = subjects.subject_id OR period_five.subject_id = subjects.subject_id OR period_six.subject_id = subjects.subject_id OR second_exam.subject_id = subjects.subject_id
ORDER BY subjects.subject_name";
$result_set = mysqli_query($connection, $query);
if(!$result_set){
die("Database query failed. Error from second semester report: ".mysqli_error($connection)." Error number is: ".mysqli_errno($connection));
}
// Test if there was a query/syntax error
//confirm_query($result_set);
return $result_set;
}
有时候我很难做到这一点可以做得更好,但遗憾的是我不知道怎么做。
有更好的方法吗?此外,只有70%的学校在其他时期使用不同方式计划学年。有没有办法以学校可以指定学年的期间或期限的方式来定制这个,并为每个期间或期限创建一个表格?
将欣赏实际意义和建议。感谢!!!!