Current location: Hot Scripts Forums » Programming Languages » PHP » tree structure


tree structure

Reply
  #1 (permalink)  
Old 01-30-04, 07:54 AM
eboiteanu eboiteanu is offline
New Member
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
tree structure

Hi,

I want display a tree menu structure like that:

- category1
- subcategory11
-subcategory 111
-subcategory 112
-subcategory 113
+ subcategory 12
+subcategory 13
+category2
....
(like menu of http://msdn.microsoft.com/library/de...commandids.asp, left side)


My dates resides in mysql table folders with fileds:
id //auto_increment
parent_id //id of category
name //name of category


I'm create following script:

<?
include_once"config/config.php"; // my config to connect mysql
$sql1 = "SELECT * FROM folders WHERE parent_id = '0'";
$result1 = mysql_query($sql1) or die(mysql_error());
while ($na1 = mysql_fetch_array($result1))
{
$category = $na1['id'];
$categorydesc = $na1['name'];
echo"<a href='http://magda/index.php?id=$category'>$categorydesc</a><br>";
if($id == $category)
{
$sql2 = "SELECT * FROM folders WHERE parent_id = '".$category."'";
$result2 = mysql_query($sql2) or die(mysql_error());
while ($na2 = mysql_fetch_array($result2))
{
$subcategory = $na2['id'];
$subcategorydesc = $na2['name'];
echo"<a href='http://magda/index.php?id=$subcategory'>$subcategorydesc</a><br>";
}
}
}
?>

That script display me a tree structure but just to level2 ...

Please help me with some sugestions,
Eugen
Reply With Quote
  #2 (permalink)  
Old 02-01-04, 03:35 PM
eboiteanu eboiteanu is offline
New Member
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
more information

I try with another way but not display the tree structure very well ...

function build_category_tree_sitemap1(&$output, $parent, $indent="") {




$qid = db_query("SELECT id, name FROM folders WHERE parent_id = $parent");

while ($cat = db_fetch_object($qid)) {


$output .=$indent."<br><a href=http://magda/backoffice/items/addkoppeling.php?id1=".$cat->id.">".$cat->name."</a>".$cat->id."<br>";
if ($cat->id !== $parent) {
build_category_tree_sitemap1($output, $cat->id, $indent."<br>&nbsp;&nbsp;");
}
}

}

$qid0 = db_query("SELECT id, name FROM folders WHERE parent_id = 0");
while(list($id,$name)=mysql_fetch_row($qid0)){
echo"<a href=http://magda/backoffice/items/addkoppeling.php?parent=$id>$name</a><br>";

build_category_tree_sitemap1($category_options,$id 1);



echo"$category_options";}
?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help finding a JavaScript Tree menu.. Stunnedmonkey JavaScript 1 08-11-04 10:09 AM
Calendar with data from directory structure Xirtam PHP 4 06-20-03 12:51 AM


All times are GMT -5. The time now is 08:09 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.