class initialising itself over and over again?
Posted: Mon Sep 01, 2003 4:22 am
Hei,
I got a wiered problem. I try to make a tree-like-structure. The nodes having an array for the childs. My prob is now that when the first child will be inserted the amount of elements in the array is 0 before and 1 after the insertion... which is quite ok... but now.. when the next one is going to be inserted, the size of the array is again 0 and 1 after.
Can anyone help me? My code is below.
Big thx in advance.
Peace,
LoCal
The classes:
baumschule.php
classes.php
I got a wiered problem. I try to make a tree-like-structure. The nodes having an array for the childs. My prob is now that when the first child will be inserted the amount of elements in the array is 0 before and 1 after the insertion... which is quite ok... but now.. when the next one is going to be inserted, the size of the array is again 0 and 1 after.
Can anyone help me? My code is below.
Big thx in advance.
Peace,
LoCal
The classes:
baumschule.php
Code: Select all
<?php
//$CR="\n\r";
$CR="<br />";
//session_register("uid");
$uid=39;
$first=true;
include("../phpdb.php");
include("classes.php");
echo("<b>Chili:</b> Freust du dich auf die Tour mit dem neuen Straßenflitzer 2.8?".$CR.
"<b>Bernd:</b> Lass mich überlegen - nein!".$CR.$CR);
$rs = ibase_query($intranet, "SELECT * FROM favoriten_ordner WHERE UID=".$uid."ORDER BY ID");
while($row = ibase_fetch_object($rs)){
if($first) {
$treeї0]=new node;
$treeї0]->setID($row->ID);
$treeї0]->setMID($row->MASTER);
$treeї0]->setName($row->NAME);
$first=false;
} else {
array_push($tree, new node);
$treeїcount($tree)-1]->setID($row->ID);
$treeїcount($tree)-1]->setMID($row->MASTER);
$treeїcount($tree)-1]->setName($row->NAME);
processActNode($tree, $treeїcount($tree)-1]);
}
}
function processActNode(&$tree, &$actnode) {
$parent=findParent($tree, $actnode->getMID());
$actnode->setParent($parent);
$parent->addChild($actnode);
}
function findParent(&$tree, $mid) {
for($i=0;$i<count($tree);$i++) if($treeї$i]->getID()==$mid) return $treeї$i];
}
echo($CR."<table><tr bgcolor='#dde1ea' align='center'><td align='center'>Name</td><td align='center'>ID</td><td>Master</td><td align='center'>AnzahlKinder</td><td align='center'>Eltern</td></tr>");
for($i=0;$i<count($tree);$i++) echo("<tr><td align='center'>".$treeї$i]->getName()."</td><td align='center'> ".$treeї$i]->getID()."</td><td align='center'>".$treeї$i]->getMID()."</td><td align='center'>".$treeї$i]->getAmountOfChildren()." </td><td align='center'>".$treeї$i]->getParent()."</td></tr>");
echo("</table>".$CR);
?>Code: Select all
<?php
class node {
var $id=-1;
var $mid=-1;
var $parent;
var $children;
var $name;
var $isLink=true;
function setId($id) {
$this->id = $id;
}
function setMid($mid) {
$this->mid = $mid;
}
function setParent(&$parent) {
$this->parent = $parent;
}
function addChild(&$child) {
if(count($this->children)<=0)$this->childrenї0]=$child;
else array_push($this->children,$child);
}
function setName($name) {
$this->name = $name;
}
function setIsLink($isLink) {
$this->isLink = $isLink;
}
function getID() {
return $this->id;
}
function getMID(){
return $this->mid;
}
function getParent() {
return $this->parent;
}
function getChildren() {
return $this->children;
}
function getAmountOfChildren() {
return count($this->children);
}
function getChild($i) {
return $this->childrenї$i];
}
function getName() {
return $this->name;
}
function isLink() {
return $this->isLink;
}
}
?>