I have a SQLite database with a table of 8000 entries. Each row in this table has a “parent” column which refers to another element in the same table.
What would be the most efficient way to load this table into an easier to access tree-variable?
The “recursive” way is too slow:
function BuildMap($top = 0)
{
global $allmap;
if ($top == 0)
{
$q1 = Q("SELECT * FROM ORGCHART WHERE PARENT = 0 ORDER BY NAME ASC");
while($r1 = $q1->fetchArray())
{
// Save to an array code here
...
BuildMap($r1['ID']);
}
}
else
{
$q2 = Q("SELECT * FROM ORGCHART WHERE PARENT = ? ORDER BY NAME ASC",array($top));
while($r2 = $q2->fetchArray())
{
// Save to an array code here
...
BuildMap($r2['ID']);
}
}
}