You are here: Re: Grouping system « PHP SQL « IT news, forums, messages
Re: Grouping system

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация