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


February 6, 2009 at 2:19 am |
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
February 6, 2009 at 4:43 am |
I will mail you some code examples, hope it will help you.
regards,
kumar.
September 17, 2009 at 7:43 am |
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}’ />”;
}
}
September 17, 2009 at 7:44 am
id} is dollar id
February 13, 2009 at 12:46 am |
Thankyou very much for the solution… i wasted lot of time on this…
June 10, 2009 at 7:28 am |
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