Reputation: 71
I want to create a system in php
and mysql
, that is supposed to calculate student grades and display the results, such that the school can print out a report card.
When a teacher logs onto the system, he/she will only see the students he/she teaches
I already have three tables in the database (teachers
table, students
table, subjects
table).
A teacher teaches more than one subject and a teacher teaches more than one class.
How can I implement that in the database?
Upvotes: 1
Views: 1191
Reputation: 23078
This question is not really appropriate for StackOverflow, but I will try to get you started by providing a first draft for your tables:
TeacherId INT NOT NULL Primary key Autogenerated
FirstName VARCHAR(100)
LastName VARCHAR(100)
StudentId INT NOT NULL Primary key Autogenerated
FirstName VARCHAR(100)
LastName VARCHAR(100)
SubjectId INT NOT NULL Primary key Autogenerated
SubjectName VARCHAR(100)
TeacherXSubjectId INT NOT NULL Primary key Autogenerated
TeacherId INT NOT NULL FK -> Teacher
SubjectId INT NOT NULL FK -> Subject
an unique key should be placed on (TeacherId
, SubjectId
)
ClassId INT NOT NULL Primary key Autogenerated
ClassName VARCHAR(100)
TeacherXClassId INT NOT NULL Primary key Autogenerated
TeacherId INT NOT NULL FK -> Teacher
ClassId INT NOT NULL FK -> Class
an unique key should be placed on (TeacherId
, ClassId
)
ClassXStudentId INT NOT NULL Primary key Autogenerated
ClassId INT NOT NULL FK -> Class
StudentId INT NOT NULL FK -> Student
Grade INT -- type may depend on how the grade looks (numeric vs. A, B, ...)
For the first request: see the students he/she teaches
SELECT S.*
FROM Student S
INNER JOIN ClassXStudent CxS ON CxS.StudentId = S.StudentId
INNER JOIN TeacherXClass TxS ON TxS.ClassId = CxS.ClassId
WHERE T.TeacherId = <current teacher id>
Give it a try and come back with more targeted questions :).
Upvotes: 1