Tree structure with data from database : “php Programming ” is backend

creating Tree structure with data from the database with PHP programming.here there are three things to consider i have given  them as points below follow them
1. define a http servive in ur flex application with properties resultFormat and result, including the url (the data from database or program)

<mx:HTTPService id=”newtree” useProxy=”false”  url=”http://wdoserver/kumar/treeread.php”  resultFormat=”e4x” result=”readMe(event)”/>

2. The PHP program which sends data as an xml it is given below, for progrmming write the similar tags in echo it gives out.
<node>
<node data=”mybook”>
<node data=”mybook”/>
<node data=”mybook”/>
</node>
<node data=”mybook”/>
<node data=”mybook”/>
</node>

3. get that data in ur tree tag with properties dataprovider , showroot ,and labelfield

<mx:Tree x=”10″ y=”10″ width=”330″ height=”523″ labelField=”@data” showRoot=”false” id=”contenttree” change=”treeChanged(event)”>
</mx:Tree>

finally get that result in a method as defined readMe(event) in httpservice

private function readMe(event:ResultEvent):void
{
contenttree.dataProvider=event.result ;
}

thats it ur tree structure from database is ready now play with it.

As few readers requested some code example i am giving it here.Enjoy

Code Example: Download Here

6 Responses to “Tree structure with data from database : “php Programming ” is backend”

  1. Larry Johnson Says:

    Could you post the PHP code to produce the xml? I am having a terrible time getting the data into the nested xml format. I have the data flat in a table with the columns:
    ID
    Type (parent or child)
    Parent ID
    Label

    • kumargandhi Says:

      I will mail you some code examples, hope it will help you.

      regards,
      kumar.

    • Efrain Atienza Says:

      For example using doctrine and a n-ary tree database structure:

      private function category($id) {
      $category = Doctrine_Query::create()
      ->where(‘id = ?’, array($id))
      ->from(‘categories’)
      ->fetchOne();
      $subcategories = Doctrine_Query::create()
      ->where(‘idParent = ?’, array($id))
      ->from(‘categories’)
      ->orderby(‘order ASC’)
      ->execute();
      if (count($subcategories)) {
      echo “id}’ title=’{$category->title}’>”;
      foreach ($subcategories as $subcategory) {
      $this->category($subcategory->id);
      }
      echo “”;
      } else {
      echo “id}’ title=’{$category->title}’ />”;
      }
      }

  2. MS Says:

    Thankyou very much for the solution… i wasted lot of time on this…

  3. Pradip Jadhav Says:

    Hi Kumar,

    I have some problem. I created a tree structure as u told.

    Now problem is that i want to expand first node of a tree.

    Please help me to solve this.

    Thanks in advance

    Regards,
    Pradip Jadhav

Leave a Reply