Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
User Hierarchy
Message
From
04/03/2004 08:23:17
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00883041
Message ID:
00883044
Views:
10
First of all, in general, this kind of hierarchical tree calls for a structure similar to this:
* List of fields
UserId
ParentId
UserCode
UserName
* (other relevant fields)
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)
Previous
Reply
Map
View

Click here to load this message in the networking platform