I use the following data and function successfully on another page that has lots of other stuff going on (and a test page with only this bit):
while (list($catID, $catNameSelect, $catParentSelect) = mysqli_fetch_array($catResult, MYSQLI_BOTH)) { $categoryNR[(string)$catID] = $catID; $categoryNames[(string)$catID] = $catNameSelect; $catParent = (string)$catParentSelect; if(!array_key_exists($catParent, $childrenTree)) $childrenTree[$catParent] = array(); $childrenTree[$catParent][] = (string)$catID; }function renderTree($parent = 0, $subCounter = 0){global $cid;global $categoryNR; global $categoryNames; global $childrenTree; if($parent != 0) { echo "<option value=\"webster.php?cid=" . $categoryNR[$parent] . "\""; echo " style=\"padding-left:" . $subCounter . "px;\">", $categoryNames[$parent], "</option>\n"; $subCounter = $subCounter + 10; } $children = $childrenTree[$parent]; if(count($children) > 0) { //If node has children foreach($children as $child) renderTree($child, $subCounter); } }renderTree(); //This renders the hierarchical tree
However, on the relevant page it shows drop down ok, but when you look in code you can see that there is an issue...Undefined variable: childrenTreearray_key_exists() [<a href=function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object I do not get this. It is working fine on other page/s with same query and the lot. Why is it saying that childrenTree is not defined in this case? Where could I look? Thanks,Son