Reputation: 59
What I mean is I have 2 tables, one is a table of estudents and the second is a table of courses that they are registered. Ex of courses table
------------------------
id_estudent id_course
------------------------
| 1 | 2
| 1 | 3
| 2 | 2
------------------------
If I have 10 different courses, I want to know how to show a checbox to register to new courses, one checkbox for course, but only show the courses that the student are not registered, not show the courses that he are registered.
For example, if the student number 1 is registered for courses two and three show checbox for the One, Four, Five... but not for the Two and Three And if the student check one or various checkbox insert its to the mysql table.
Upvotes: 1
Views: 80
Reputation: 735
You can collect first IDs of already registered courses and then use NOT IN statement to exclude those courses:
SELECT * FROM full_courses WHERE id NOT IN (SELECT id_course FROM courses WHERE id_estudent = $estudent_id)
Where full_courses
is table with courses, courses
table with registered courses to estudents (the same table which in example), and $estudent_id
is ID of student that you want to show courses.
Upvotes: 3