I really hope someone can help me with this. I’m struggling with it for nearly two days now…
I have a DB-table “Device” and a table “Connection”. I’m using it to visualize my company’s network. To pass the data to the JS-framework I use to visualize the data I need an array like this:
Array
(
[id] => 1
[name] => TestPC1
[children] => Array
(
[0] => Array
(
[id] => 2
[name] => Testhub 2
[data] => Array
(
)
[children] => Array
(
[0] => Array
(
[id] => 3
[name] => Rack3
[data] => Array
(
)
[children] => Array
(
)
)
[1] => Array
(
[id] => 4
[name] => Rack4
[data] => Array
(
)
[children] => Array
(
)
)
)
)
)
)
The device-table looks like this:
A | B
-------------------
1 | 2
2 | 3
2 | 4
The visualization of this example looks like this:
http://img34.imageshack.us/img34/4230/netmd.jpg
Does anyone have an idea, how to get from the db-data to this array?
Thank you.
Let’s say you want to do it in PHP using that table, for example’s sake I’ll use an array to represent the returned database data after a
JOINbetween the given table and what I imagine is an ID->Name mapping table:Personally I wouldn’t bother patching up the indices, it will make it easier searching for entries by ID later if you don’t.
Be careful when entering your parent/child data or you’ll wind up with a lovely circular reference.
You will of course need to replace the references to
$linkswith a suitable db command that produces an array (mysql_fetch_array etc).