Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6707553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:39:12+00:00 2026-05-26T07:39:12+00:00

I have a tree structure in my database, eg for employees. create table employees

  • 0

I have a tree structure in my database, eg for employees.

 create table "employees" (employee_id, name, manager_id);

where, of course, manager_id is the employee_id (same table) with the manager of that employee.

This can easily be converted to an array, representing the tree structure of the company
(although there is not 1 CEO at the top, the root-node has multiple elements). All fine so far.

Now, to handle registrations, i have an array of employee_ids

 $registrations = array(3,7, 10);

I’d need to show those in the tree structure, where only the managers of those employees are shown (but up to the top of the tree). Does anybody have an algorithm for this? I managed to add them to the tree, but didn’t manage to putg the different branches together when 2 people share 1 manager.

Say employee 3 and 10 (cfr above) share the same manager with ID 15, and employee 7 has manager with ID 23, where both managers report to the same manager with ID 33, who in his turn reports to 45: I’d need an array

array('45'=>array('33'=>array('23'=>array(7), '15'=>array(3,10))));

I do manage to build this structure, eg starting with employee 3, I get

array('45'=>array('33'=>array('15'=>array(3))));

and while looping for employee 7, I manage to build the branch

array(23->array(7))

but how can i now merge this new array in the already existing one … ? I know that the manager of 23 is 33, but how do I a) find that it needs to be added to the tree, and b) add it to the tree ath the correct place??? anybody?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:39:12+00:00Added an answer on May 26, 2026 at 7:39 am

    My opinion is that you have chosen the wrong way to store tree data into your database.

    If you like to store tree data into your database you have to use Modified Preorder Tree Traversal.

    More information about this way of storing trees in database you can find here : http://www.sitepoint.com/hierarchical-data-database/

    With this algorithm you can manage your data in any order you like and you can easily extract whatever information you like!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in my database which stores a tree structure. Here are
I have a table in my database where I store a tree structure using
I have a tree-style database with the following structure: Table fields: NodeID int ParentID
I have a tree structure in memory that I would like to render in
I have a tree structure that can be n-levels deep, without restriction. That means
I have a tree data structure that is L levels deep each node has
I have a sort of tree structure that represent a hierarchy of layers in
So I have a tree structure in a SQL-Server database. Each node is linked
I have a tree-like structure to my database in an app I am writing
I happen to have a database with a table that holds all possible combination

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.