I have an employees table and some of the employees are managers. I need a function that takes an employee ID and creates a multi-dim array with all the employees that report to them. So far I was able to print the tree:
function drillDownStaff($emplid){
$conn = db_connect();
$sql = "SELECT
employees.EmployeeID, employees.ManagerID
FROM
employees
WHERE
employees.ManagerID = '".$emplid."';
$result = mysql_query($sql,$conn);
while($row = mysql_fetch_assoc($result)){
echo "<ul>";
echo "<li>".$row['FullName'];
drillDownStaff($row['EmployeeID']);
echo "</li>";
echo "</ul>";
}
}
This will print out a nice manager->employee tree:
- John
- Jane
- Paul
- Maria
- Mark
- Tony
- Blane
- Jane
- Colleen
- Roxy
- Foxy
- Lilly
- Maureen
But what I'd like is the recursive function to return a multi-dim array with the employee tree like so:
array(
[5] => array(
[FullName] => John
[...] => Other emp details
[manages] => array(
[6]=>array(
[FullName]=>Jane
[...]=>other emp details
[manages]=> array(Pauls' details)
)
[7]=>array(...) // emp details again
)
)
)
Is this possible?
var_dumpit and show its structure?