I have 3 tables; teachers table, subjects table and events table.
1.There is one to many relationship between subjects and teachers, that is each teacher can teach only one subject but, many teachers can teach same subjects.
2.There is a many to many relationship between teachers and events.
Example of subjects table
id(PK) | name
-------------------
1 | php
-------------------
2 | java
-------------------
3 | python
-------------------
4 | c++
--------------------
5 | c#
Example of teachers table
id(PK) | name | subject_id(FK to subjects.id)
----------------------------------
1 | messi | 2
----------------------------------
2 | ronaldo | 4
----------------------------------
3 | pele | 1
----------------------------------
4 | maradona | 2
Example of events table
id(PK) | venue | subject_id (FK to teacher.id) | teacher_id(FK to subject.id)
-----------------------------------------------------------------------------------------------
1 | location1 | 2 | has to be either 1 or 4
-----------------------------------------------------------------------------------------------
2 | location2 | 1 | has to be 3 only
------------------------------------------------------------------------------------------------
3 | location3 | 4 | has to be 2 only
------------------------------------------------------------------------------------------------
4 | location4 | 4 | has to be 2 only
How do i get a foreign key
drop down menu in teacher_id
field with available options based on assigned value in subject_id
? if not possible atleast an error message after clicking go
in data insert section in phpmyadmin
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…