rendered paste body// prepares the tree; selects all nodes that we needfunction prepareTree() { if (!$this->is_prepared) { $this->prepareNetwork(); } $query = " SELECT DISTINCT r.node_id, r.node_id_relation FROM node_relation r WHERE r.node_id IN (".$this->node_id ; $nr = count($this->stats[$this->max_degree-1]); for($i = 0; $i < $nr; $i++){ if($i != $nr) { $query .= ","; } $query .= $this->stats[$this->max_degree-1][$i]; } $query .= ")"; $result = $this->db->Execute($query); if (isset($result->fields)) { $this->relation_list = array(); while(!$result->EOF) { $this->relation_list[$result->fields['node_id']][] = $result->fields; $result->moveNext(); } $result->Close(); } else { // Do some error-stuff } }// gets the nodes "friends"function selRelations($node_id) { if (isset($this->relation_list[$node_id])) { $tmp = $this->relation_list[$node_id]; unset($this->relation_list[$node_id]); return $tmp; } return array(); }function createNetwork($node_id=null, $degree=0, $path=null){ if (!isset($path)) { $path = array(); } if(empty($node_id)){ $node_id = $this->node_id; $path[] = $node_id; $this->tree = array(); } else { $path[] = $user_id; $temp1 = array( "relation" => $path, "node_id" => $node_id, "degree" => $degree); $this->tree[$node_id][] = $temp1; } if($degree < $this->max_degree) { $tmp = $this->selRelations($node_id); //print_r($tmp); if(!empty($tmp)){ foreach($tmp as $key => $i){ if(!in_array($i['node_id_relation'],$path)) { $this->tree = $this->createNetwork($i['node_id_relation'], ($degree+1), $path); } } } return $this->tree; } else { return $this->tree; } }