Posted by no on 06/29/05 16:10
On Mon, 27 Jun 2005 20:58:18 GMT, Gnutt Halvordsson
<gnutt@shell.linux.se> wrote:
>So I should always be able to see those In the group, and people above it.
The simplest from a database point of view would be a structure like:
id INT individual's id
parent_id INT id of the parent record
name VARCHAR person's name
For any record you can always know the parent_id ... and to get the
children you just need to select on all those users who have a
parent_id of you current record. It would involve recursion to see the
whole branch above your current node but it is simple and works.
Untested pseudo code (using PEAR DB):
function get_children($parent) {
global $db;
$result=$db->query('SELECT * FROM users WHERE
parent_id="'.$parent.'");
while ( ($userArray = $result->fetchRow(DB_FETCHMODE_ASSOC)) )
{
echo $userArray['name'];
get_children($userArray['id']);
}
}
Each call to the function selects the children of the current id and
then the function recurses into the tree...
Chris
[Back to original message]
|