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>

[showmyads]
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

Advertisements

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.

    • 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: