I need to get a list of employees out of a database table.
I need to end up with an array of ids (primary keys) such as
Array(03,9,2,5, 1)
The employee table has a self reference so that each record has a parentID and a level. For example
In this example, Harry is the top manager. He has two managers under him, John and Smith, further more Smith has Jane under him. (get your mind out of the gutter!)
Instead of the recursive function calling the database each time to get an id, I'll do one call and put the entire employee table in an array of assoc array(id, parentID) since there's only several records.
[PHP]
Array(
[0] = Array("
["id"] = 12,
["parentID"] = 15
)
[1] = Array (......and so on, you get the point)
[/PHP]
The recursive function will be given the primary id of the employee I need to build for. The returned array list will contain this id along with every employee under him, going down the tree as needed. I'll do one more thing, i'll even give you the employee array (shown above) as the second parameter like so:
function Recursive($_SES SION['employeeID'], $employeeArray)
{
// do magic here
}
does anybody get the idea? I never really liked recursive functions, but If I build it, i'll post it here.
thanks,
Dan
I need to end up with an array of ids (primary keys) such as
Array(03,9,2,5, 1)
The employee table has a self reference so that each record has a parentID and a level. For example
Code:
id_____parentID____Level________Name 12_____15__________1_____________John 15_____-1__________0_____________Harry 19_____15__________1_____________Smith 20_____19__________2_____________Jane
Instead of the recursive function calling the database each time to get an id, I'll do one call and put the entire employee table in an array of assoc array(id, parentID) since there's only several records.
[PHP]
Array(
[0] = Array("
["id"] = 12,
["parentID"] = 15
)
[1] = Array (......and so on, you get the point)
[/PHP]
The recursive function will be given the primary id of the employee I need to build for. The returned array list will contain this id along with every employee under him, going down the tree as needed. I'll do one more thing, i'll even give you the employee array (shown above) as the second parameter like so:
function Recursive($_SES SION['employeeID'], $employeeArray)
{
// do magic here
}
does anybody get the idea? I never really liked recursive functions, but If I build it, i'll post it here.
thanks,
Dan
Comment