First of all, in general, this kind of hierarchical tree calls for a structure similar to this:
UserId
ParentId
UserCode
UserName
Sample data:
UserId ParentId UserCode UserName
1 0 A John
2 1 B Mary
3 1 C Robert
...
Of course, you could omit the field UserCode, and shift its contents to UserId instead - depending on how you like to set up your primary keys. I am assuming that UserId is a sequential number, and UserCode, a code that the user sees.
Note that there will always be one or more top-level records that have no ParentId (ParentId = 0, or perhaps NULL).
Then, you will need to save UserId to the record you want to control.
Finally, you will need a function that takes the UserId from a record, and goes up the tree, until it finds a match for the current user (return .T.) or until it can get no further, because ParentId = 0 (return .F.). A simple
do while loop should suffice.
HTH,
Hilmar.
>Our database system requires a hierarchy of users like so:
> A
> / \
> B C
> / \ / \
> d e f g
> /\
> h i
>
>User B can see/edit records allocated to B, d, e, h and i, but cant see any others. User d can see records allocated to them, h and i only, and so on.
>
>How would you set this up in a database?
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)