AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Baumstruktur kopieren (MySQL/PHP)

Ein Thema von fillibuster · begonnen am 15. Mai 2013 · letzter Beitrag vom 21. Mai 2013
 
fillibuster

Registriert seit: 3. Nov 2010
Ort: Coesfeld
245 Beiträge
 
Delphi 2010 Professional
 
#11

AW: Baumstruktur kopieren (MySQL/PHP)

  Alt 21. Mai 2013, 10:11
Hallo,

habe jetzt die Lösung mit PHP umgesetzt, aber irgendwo befindet sich noch ein Fehler, daher möchte ich euch noch einmal um Hilfe bitten:
Code:
    /**
     * Copy a single node and return the new id
     *
     * @param $data
     * @return mixed
     */
    public function copyNode($sn_data){
        $this->db2->insert('items_configurations', $sn_data);
        return $this->db2->insert_id();
    }

    /**
     * Return a list of child nodes as an assoziative array
     * from a given parent
     *
     * @param $parent_id
     * @return mixed
     */
    public function childList($parent_id){
        $tmp = 'SELECT parent_id,item_id,template_id,position FROM items_templates WHERE parent_id='.$parent_id;
        $query=$this->db2->query($tmp);
        return $query->result_array();
    }


    /**
     * Copy the whole tree structure through an recursive function
     *
     * @param $node_data
     */
    public function copyTree($node_data){
        $new_parent = $this->copyNode($node_data);
        $new_data  = $this->childList($node_data['parent_id']);
        if(is_array($new_data)){
            foreach($new_data as $new_node_data) :
                $new_node_data['parent_id'] = $new_parent;
                $this->copyTree($new_node_data);
            endforeach;
        }
    }
Die Daten übergebe ich als assoziatives Array. Der Aufruf (erster Datensatz des Baumes (parent_id=0,position=1) sieht dann z. B. so aus:
Code:
$this->copyTree(array('parent_id' => 0,'item_id' => 40,'template_id' => 6,'position' => 1));
Allerdings wird nur der nächste Knoten kopiert und ich sehe meinen Fehler (PHP sagt: Invalid argument supplied for foreach()) nicht?!

Geändert von fillibuster (21. Mai 2013 um 10:50 Uhr)
  Mit Zitat antworten Zitat
 

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:24 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz