Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hei :)

Ich habe hier (doch) ein kleineres Problem. Die Quellen zu dem ganzen sind unten.

Das wird eine art Baumstruktur. Wenn ich nun einen knoten habe, der Eltern hat, dann hol ich mir das "Elternteil" und setzte da mti addChild() ein Kind dazu. Sollte ja soweit funktionieren.. nur hier is das so, dass wenn ich ein weiteres Kind hinzufüge, dass die "alten" weg sind..

Also ich such jetzt schon ewig den Fehler.. findet jemand von euch was?

Big thx.

Peace,

LoCal

hier der Code:

baumschule.php


<?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.$CR);

$rs = ibase_query($intranet, "SELECT * FROM favoriten_ordner WHERE UID=".$uid."ORDER BY ID");

while($row = ibase_fetch_object($rs)){

	if(!$first) array_push($tree, new node);

	else $tree[0]=new node;

	echo($row->NAME." ".$row->ID."<br />");

	$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], $first);

	$first=false;

}


function processActNode(&$tree, &$actnode, $first) {

	//echo("ID=".$actnode->getID()." Master=".$actnode->getMID()."<br />");

	if(!$first) {

		$parent=findParent($tree, $actnode->getMID());

		$actnode->setParent($parent);

		$parent->addChild($actnode);


			for($i=0;$i<$parent->getAmountOfChildren();$i++) {

				echo("Child->: ".$parent->getChild($i)." ..<br />");

			} 

		}


}


function findParent(&$tree, $mid) {

	for($i=0;$i<count($tree);$i++)  {

		if($tree[$i]->getID()==$mid) return $tree[$i];	

	}

}


echo($CR."<table border=1>");

	echo("<tr><td>Name: </td><td>ID:  </td><td>Master:  </td><td>AnzahlKinder: </td><td>Eltern: </td></tr>");


for($i=0;$i<count($tree);$i++) {

	echo("<tr><td>".$tree[$i]->getName()."</td><td> ".$tree[$i]->getID()."</td><td>".$tree[$i]->getMID()."</td><td>".$tree[$i]->getAmountOfChildren()." </td><td>".$tree[$i]->getParent()."</td></tr>");

}

echo("</table>".$CR);

?>

classes.php

<?php


class node {


	var $id=-1;

	var $mid=-1;

	var $parent;

	var $children;

	var $name;

	var $isLink=true;

	var $foo;


	function node() {

		$this->children=array();

		$this->isLink=true;

	}


	function setId($id) {

		$this->id = $id;

	}


	function setMid($mid) {

		$this->mid = $mid;

	}


	function setParent(&$parent) {		

		$this->parent = $parent;

	}


	function addChild(&$child) {

		echo("link: ".(int)$this->isLink."<br />"); // zum Test

		$this->isLink=false; //zum Test

		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;

	}

}


?>


function setParent(&$parent) {

    $this->parent = $parent;

}
ich glaube, das mußt du so machen:

function setParent(&$parent) {

    $this->parent = &$parent;

}
bei der verwendung von findParent solltest du prüfen, ob auch ein elter gefunden wurde.

while($row = ibase_fetch_object($rs)) {

    if(!$first) array_push($tree, new node);

    else $tree[0]=new node;


    echo($row->NAME." ".$row->ID."<br />");

    $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], $first);

    $first=false;

}
Du kannst die Indizes auch automatisch numerieren:

while($row = ibase_fetch_object($rs)) {

    $tree[] = new node;

    echo($row->NAME." ".$row->ID."<br />");

    $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], count($tree) == 1); 

   // count($tree) == 1 läßt sich auch in processActNode prüfen

}

Danke... aber das hat mir lieder nix geholfen. Mein Problem ist das mit dem "Kind". Das mit dem parent funzt 100%.

Aber bei child ist halt so, dass scheinbar der array irgendwie geleert wird.

trotzdem Danke.

Ich glaube, das Problem liegt bei findParent,

die Funktion gibt keine Referenz auf das eigentliche Objekt wieder:

return $tree[$i];

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.