php - Recursively linking records -
i have table timeslots users can sign for. on administrative end, admin-user can choose 'link' 2 timeslots together, says end-user, 'if sign 1 of these timeslots, must sign other timeslots linked it.' these links stored in table has 2 columns, 1 being id of timeslot requiring link, , other being id of timeslot being linked to.
how can make such when linking 1 timeslot another, both depend on other being selected. needs recursive other linked timeslots well, following example:
admin says: #1 linked #2 #3 linked #2 therefore: #1 linked #2 #2 linked #1 #3 linked #2 #2 linked #3 #3 linked #1 #1 linked #3
what best way accomplish this? right i'm trying put information link table, if there's way can more php , less sql work also. provide code sample, don't think helpful.
edit: conceptual answers fine. don't need code written me unless demonstrative purposes.
one approach may table of 2 columns in form of: node_id, , link_id.
in case, node_id timeslot id. example above, rows be:
1 1 2 1 3 1
where 1, 2, 3 in first column timeslots, , 1 in second link.
hypothetically let's add timeslots 4, 5, 6, 7, , 8 links 2, 3, , 4.
4 2 5 3 6 2 7 4 8 2
this translates to:
pick 4, must pick 6 , 8 (all link 2). pick 5, you're done (only member of link 3). pick 6, must pick 4 , 8 (all link 2). pick 7, you're done (only member of link 4). pick 8, must pick 4 , 6 (all link 2).
Comments
Post a Comment