I have a table with timeslots that users can sign up for. On the administrative end, the admin-user can choose to ‘link’ two timeslots together, which basically says to the end-user, ‘If you sign up for one of these timeslots, you must sign up for all other timeslots that are linked to it.’ These links are stored in another table which has two columns, one being the ID of the timeslot requiring a link, and the other being the ID of the timeslot that is being linked to.
How can I make it such that when linking one timeslot with another, BOTH depend on the other being selected. This needs to be recursive for other linked timeslots as well, like the following example:
Admin says:
#1 is linked to #2
#3 is linked to #2
Therefore:
#1 is linked to #2
#2 is linked to #1
#3 is linked to #2
#2 is linked to #3
#3 is linked to #1
#1 is linked to #3
What is the best way to accomplish this? Right now I’m trying to put that information into a link table, but if there’s another way that I can do it with more PHP and less SQL that would work also. I would provide a code sample, but I don’t think that it would be helpful.
Edit: Conceptual answers are fine. I don’t need code written for me unless for demonstrative purposes.
One approach may be a table of two columns in the form of: Node_Id, and Link_Id.
In this case, Node_Id is the Timeslot ID. For the example above, the rows would be:
Where 1, 2, 3 in the first column are timeslots, and the 1 in the second is the link.
Hypothetically let’s add timeslots 4, 5, 6, 7, and 8 with links 2, 3, and 4.
This translates to: