简体   繁体   English

表中的php mysql关系定义

[英]php mysql relational definition in tables

guys I've been trying to create create a school results management system.There is a STUDENT table and many COURSE tables.伙计们,我一直在尝试创建一个学校成绩管理系统。有一个STUDENT表和许多COURSE表。 Each student must be linked to all Courses tables.每个学生都必须链接到所有课程表。 eg JOHN, MARY,PETER must partake in MATHEMATICS, ENGLISH, ELECTROPHYSICS, PROGRAMMING etc例如JOHN, MARY,PETER必须参加MATHEMATICS, ENGLISH, ELECTROPHYSICS, PROGRAMMING
My problem is how to define this relationship in mysql and at same time let these students fetch only their own results in all the courses.我的问题是如何在 mysql 中定义这种关系,同时让这些学生在所有课程中只获取他们自己的结果。

I don't know if you have a requirement to have each course in a separate COURSE table but that doesn't make much sense.我不知道您是否要求将每门课程都放在单独的 COURSE 表中,但这没有多大意义。 You should have a STUDENT table and a COURSES table.您应该有一个 STUDENT 表和一个 COURSES 表。 Then, you will need a STUDENT_COURSES table to show which courses a student has taken or must take.然后,您将需要一个 STUDENT_COURSES 表来显示学生已参加或必须参加的课程。 Your table structure should be something like:你的表结构应该是这样的:

  • STUDENT: Id, Name, Gender, etc学生:ID、姓名、性别等
  • STUDENT_COURSES: Id, Student_Id, Course_Id, Taken, Grade STUDENT_COURSES: Id, Student_Id, Course_Id, Taken, Grade
  • COURSES: Id, Course_Name课程:ID,课程名称

When a new student is created, you would need to add records to the STUDENT_COURSES table to insert the new STUDENT.Id into the Student_Id field and the Course_Id for each of the required courses.创建新学生时,您需要将记录添加到 STUDENT_COURSES 表,以将新 STUDENT.Id 插入 Student_Id 字段和每个必修课程的 Course_Id。 The default value for Taken would be false and the Grade would be Null or Empty String. Taken 的默认值为 false,而 Grade 将为 Null 或 Empty String。

This is a very simplistic example and would not work in a real world solution because you would need to have Instructors, Locations, Etc. to make anything useful.这是一个非常简单的示例,在现实世界的解决方案中不起作用,因为您需要有讲师、位置等才能使任何有用的东西。 But hopefully this will help you get started.但希望这会帮助你开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM