Hi.
I have this code
<?
class nodetree {
var $keywords;
var $Title;
var $child;
var $cnode;
function add_child($Child) {
if(empty($this->child)) {
$nodenumber = 0;
} else {
$nodenumber = count($this->child);
}
echo "Agregar: $Child->keywords a $this->keywords;<BR>";
$this->child[$nodenumber] = $Child;
$this->cnode++;
}
function add_childin($Child, $parent) {
echo $this->keywords;
if ($this->keywords==$parent) {
$this->add_child($Child);
return $this;
}
$i=0;
while ($i<$this->cnode) {
$ptr=$this->child[$i];
if ($ptr) {
if ($ptr->add_childin($Child, $parent))
break;
}
$i++;
}
}
function shownode() {
$i=0;
echo "$this->keywords<BR>";
while ($i<$this->cnode) {
$ptr=$this->child[$i];
if ($ptr) {
$ptr->shownode();
}
$i++;
}
}
function findparent($mkey) {
$i=0;
if ($this->keywords==$mkey)
return $this;
while ($i<$this->cnode) {
$ptr=$this->child[$i];
if ($ptr) {
if ($mt=$ptr->findparent($mkey))
break;
}
$i++;
}
return $mt;
}
function nodetree($mkey="\\", $mTitle="Home Page") {
$this->keywords = $mkey;
$this->Title=$mTitle;
}
}
$pp = new nodetree();
$pp1 = new nodetree("0001", "car 1");
$pp2 = new nodetree("0011", "car 2");
$pp3 = new nodetree("0111", "car 3");
//$pp->add_childin($pp3, "0001");
$pp->add_child($pp2);
$pp->add_child($pp1);
$pp1->add_child($pp3);
echo $pp1->cnode;
echo "-----------------------------------<BR>";
$pp->shownode();
echo "-----------------------------------<BR>";
?>
Thi idea is create a tree using keywords but doesn't work... please anyone find a problem o get an idea!!
greetings saul