note 100472 deleted from book.array by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 Oct 2010 15:07:47 +0000 |
| Subject: | note 100472 deleted from book.array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173248@lists.php.net to get a copy of this message | ||
Note Submitter: subzey at immelman dot ru
----
To macnimble at gmail dot com:
It's more convenient (for me) to organize trees using a DOMDocument element.
<?php
$document = new DOMDocument();
$res = pg_query("SELECT id, pid, ⦠FROM ⦠ORDER BY â¦");
while ($line = pg_fetch_assoc($res)){
$element = $document->createElement("element");
$elements_by_id[$line['id']] = array(0 => $element, 1 => $line['pid']);
$element->setAttribute("id", $line['id']);
$element->setAttribute("name", $line['name']);
$element->setAttribute("â¦etcâ¦", $line['â¦etcâ¦']);
};
foreach ($elements_by_id as $element_composition){
list ($element, $pid) = $element_composition;
if (isset($elements_by_id[$pid])){
$elements_by_id[$pid]->appendChild($element);
};
};
?>
Result is the tree of DOMElements, with XPath, useful tree manupulation methods and much more.
Also, it's very extensible: actual code I used was twice that big handling all possible tree
corruption handling and the result was an UL-LI HTML tree just in place. And it also preserves ORDER
BY.