flags == 0) { return(true); } else { return(false); } } } function buildChildObjects($object, $dbd) { $sql = "SELECT id, parent, name, description, flags FROM object WHERE parent = " . $object->id; $res = mysql_db_query("gehring", $sql) or die("failed to perform query"); $childrenArrayIndex = sizeof($object->children); while ($row = mysql_fetch_row($res)) { $childObject = new Object(); $childObject->id = $row[0]; $childObject->parent = $row[1]; $childObject->name = $row[2]; $childObject->description = $row[3]; $childObject->flags = $row[4]; $object->children[$childrenArrayIndex] = $childObject; buildChildObjects($childObject); $childrenArrayIndex++; } } function buildRootObject() { $dbd = mysql_pconnect("localhost", "gehring", "rocks") or die("failed to connect to database"); mysql_select_db("gehring", $dbd) or die ("unable to select databae"); /* Obtain the root object. Additional objects will be built * on this and linked into the object structure accordingly. */ $sql = "SELECT id, parent, name, description, flags FROM object WHERE parent = 0"; $res = mysql_db_query("gehring", $sql) or die("failed to perform query"); $row = mysql_fetch_row($res); $rootObject = new Object(); $rootObject->id = $row[0]; $rootObject->parent = $row[1]; $rootObject->name = $row[2]; $rootObject->description = $row[3]; $rootObject->flags = $row[4]; /* Build child objects, * return built root object to caller. */ buildChildObjects($rootObject, $dbd); return($rootObject); } ?>