PHP Code:
// only get subcats
$cats = $DB_site->query("SELECT * FROM cats WHERE parent <> 0");
while($cat = $DB_site->fetch_array($cats))
{
$cat_cache["$cat[parentid]"]["$cat[order]"] = $cat;
}
// only get parents
$parents = $DB_site->query("SELECT * FROM cats WHERE parent=0");
while($parent = $DB_site->fetch_array($parents))
{
foreach($cat_cache as $pr)
{
foreach($pr as $order => $subcat)
{
eval here
}
}
}
Might be some errors in there, but you get the idea of how it should work. Just 2 queries.