RE: [PHP-DB] Tree structure - how to show only current branch ??

2004-03-30 Thread Galbreath, Mark A
Already been done:

http://www.destroydrop.com/javascripts/tree/

Mark

-Original Message-
From: -{ Rene Brehmer }- [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 30, 2004 7:50 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Tree structure - how to show only current branch ??


Ok, Tom Reed got my thinker running big time ... and I've been trying to 
build an expandable and modifiable tree structure where it only displays 
the branch leading to the current folder... Showing the entire tree is 
easy, but how do I change the code to only display the branch we need??? 
... I've never coded visual trees before, so this is new for me ...

Found several samples with google where the code relies on the structure 
being fixed in the DB. What I want to create is the possibility to mode 
folders around within the tree ... literally moving branches from one place 
to another, while retaining their content.

DB structure is simply this (I want to get rid of the level field if it's 
at all possible to count the levels with recursive functions, but for now 
it stays).

  folderID int(10) UNSIGNED auto-increment
  parentID  int(10) UNSIGNED
  level  tinyint(3) UNSIGNED
  name  varchar(255)

(I'm fully aware that int may be overkill, but this is for testing
purposes...)

test data:
http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree+tes
ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepeat_c
ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++ORDE
R+BY+%60folderID%60+ASCfolderID 
http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree+tes
ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepeat_c
ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++ORDE
R+BY+%60parentID%60+ASCparentID 
http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree+tes
ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepeat_c
ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++ORDE
R+BY+%60level%60+ASClevel 
http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree+tes
ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepeat_c
ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++ORDE
R+BY+%60name%60+ASCname 

1 0 0 parent 1
2 0 0 parent 2
3 0 0 parent 3
4 0 0 parent 4
5 0 0 parent 5
6 1 1 child of 1
7 3 1 child of 3
8 1 1 child 2 of 1
9 6 2 sub-child 1
10 6 2 sub-child 2
11 10 4 sub-sub 1
12 10 4 sub-sub 2
13 11 5 sub-sub-sub 1

Current code looks like this, the 2 subfunctions prints the branches, the 
main function below prints the root structure...:

function count_children($parentID) {
// count number of children in folder
   $count = mysql_query(SELECT COUNT(*) AS num_children FROM folders WHERE 
`parentID`='$parentID');
   $numrows = mysql_fetch_array($count);

   return $numrows['num_children'];
}

function print_children($parentID) {
// print the branch of sub-folders
   $children = mysql_query(SELECT folderID,level,name FROM folders WHERE 
`parentID`='$parentID');

   while($child = mysql_fetch_array($children)) {
 $folderID = $child['folderID'];
 $name = $child['name'];
 $level = $child['level'];

 for ($i = 0; $i  $level; $i++) {
   echo('middot');
 }
 echo(middot; a
href=\test1.php?folderID=$folderID\$name/abr\n);

 // let's find children... recursive call !!
 if (count_children($folderID)  0) {
   print_children($folderID);
 }
   }
}

// get root parents -- main tree function
$parents = mysql_query(SELECT folderID,name FROM folders WHERE 
`parentID`='0');

while($folder = mysql_fetch_array($parents)) {
   $folderID = $folder['folderID'];
   $name = $folder['name'];

   echo(middot; a
href=\test1.php?folderID=$folderID\$name/abr\n);

   // let's find children...
   if (count_children($folderID)  0) {
 print_children($folderID);

   }
}


The output of all this looks like this:

· http://localhost/tests/tree%20structure/test1.php?folderID=1parent 1
·· http://localhost/tests/tree%20structure/test1.php?folderID=6child of 1
··· http://localhost/tests/tree%20structure/test1.php?folderID=9sub-child
1
··· http://localhost/tests/tree%20structure/test1.php?folderID=10sub-child
2
· http://localhost/tests/tree%20structure/test1.php?folderID=11sub-sub
1
·· 
http://localhost/tests/tree%20structure/test1.php?folderID=13sub-sub-sub 1
· http://localhost/tests/tree%20structure/test1.php?folderID=12sub-sub
2
·· http://localhost/tests/tree%20structure/test1.php?folderID=8child 2 of
1
· http://localhost/tests/tree%20structure/test1.php?folderID=2parent 2
· http://localhost/tests/tree%20structure/test1.php?folderID=3parent 3
·· http://localhost/tests/tree%20structure/test1.php?folderID=7child of 3
· http://localhost/tests/tree%20structure/test1.php?folderID=4parent 4
· http://localhost/tests/tree%20structure/test1.php?folderID=5parent 5

What I wanna do is make it possible to click on, say, 'sub-child 2', and 

RE: [PHP-DB] Tree structure - how to show only current branch ??

2004-03-30 Thread Paul Miller
Ya it has - that is a great script!

-Original Message-
From: Galbreath, Mark A [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 30, 2004 7:15 AM
To: '-{ Rene Brehmer }-'; '[EMAIL PROTECTED]'
Subject: RE: [PHP-DB] Tree structure - how to show only current branch
??


Already been done:

http://www.destroydrop.com/javascripts/tree/

Mark

-Original Message-
From: -{ Rene Brehmer }- [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 30, 2004 7:50 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Tree structure - how to show only current branch ??


Ok, Tom Reed got my thinker running big time ... and I've been trying to

build an expandable and modifiable tree structure where it only displays

the branch leading to the current folder... Showing the entire tree is 
easy, but how do I change the code to only display the branch we need???

... I've never coded visual trees before, so this is new for me ...

Found several samples with google where the code relies on the structure

being fixed in the DB. What I want to create is the possibility to mode 
folders around within the tree ... literally moving branches from one
place 
to another, while retaining their content.

DB structure is simply this (I want to get rid of the level field if
it's 
at all possible to count the levels with recursive functions, but for
now 
it stays).

  folderID int(10) UNSIGNED auto-increment
  parentID  int(10) UNSIGNED
  level  tinyint(3) UNSIGNED
  name  varchar(255)

(I'm fully aware that int may be overkill, but this is for testing
purposes...)

test data:
http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree
+tes
ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepe
at_c
ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++
ORDE
R+BY+%60folderID%60+ASCfolderID
http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree
+tes
ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepe
at_c
ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++
ORDE
R+BY+%60parentID%60+ASCparentID
http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree
+tes
ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepe
at_c
ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++
ORDE
R+BY+%60level%60+ASClevel
http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree
+tes
ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepe
at_c
ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++
ORDE
R+BY+%60name%60+ASCname

1 0 0 parent 1
2 0 0 parent 2
3 0 0 parent 3
4 0 0 parent 4
5 0 0 parent 5
6 1 1 child of 1
7 3 1 child of 3
8 1 1 child 2 of 1
9 6 2 sub-child 1
10 6 2 sub-child 2
11 10 4 sub-sub 1
12 10 4 sub-sub 2
13 11 5 sub-sub-sub 1

Current code looks like this, the 2 subfunctions prints the branches,
the 
main function below prints the root structure...:

function count_children($parentID) {
// count number of children in folder
   $count = mysql_query(SELECT COUNT(*) AS num_children FROM folders
WHERE 
`parentID`='$parentID');
   $numrows = mysql_fetch_array($count);

   return $numrows['num_children'];
}

function print_children($parentID) {
// print the branch of sub-folders
   $children = mysql_query(SELECT folderID,level,name FROM folders
WHERE 
`parentID`='$parentID');

   while($child = mysql_fetch_array($children)) {
 $folderID = $child['folderID'];
 $name = $child['name'];
 $level = $child['level'];

 for ($i = 0; $i  $level; $i++) {
   echo('middot');
 }
 echo(middot; a
href=\test1.php?folderID=$folderID\$name/abr\n);

 // let's find children... recursive call !!
 if (count_children($folderID)  0) {
   print_children($folderID);
 }
   }
}

// get root parents -- main tree function
$parents = mysql_query(SELECT folderID,name FROM folders WHERE 
`parentID`='0');

while($folder = mysql_fetch_array($parents)) {
   $folderID = $folder['folderID'];
   $name = $folder['name'];

   echo(middot; a
href=\test1.php?folderID=$folderID\$name/abr\n);

   // let's find children...
   if (count_children($folderID)  0) {
 print_children($folderID);

   }
}


The output of all this looks like this:

. http://localhost/tests/tree%20structure/test1.php?folderID=1parent 1
.. http://localhost/tests/tree%20structure/test1.php?folderID=6child
of 1 ...
http://localhost/tests/tree%20structure/test1.php?folderID=9sub-child
1
...
http://localhost/tests/tree%20structure/test1.php?folderID=10sub-child
2
.
http://localhost/tests/tree%20structure/test1.php?folderID=11sub-sub
1
.. 
http://localhost/tests/tree%20structure/test1.php?folderID=13sub-sub-s
ub 1 .
http://localhost/tests/tree%20structure/test1.php?folderID=12sub-sub
2
.. http://localhost/tests/tree%20structure/test1.php?folderID=8child 2
of 1 .
http://localhost/tests/tree%20structure/test1.php?folderID=2parent 2 .
http://localhost/tests/tree%20structure/test1.php?folderID=3parent 3
.. http

RE: [PHP-DB] Tree structure - how to show only current branch ??

2004-03-30 Thread -{ Rene Brehmer }-
Eh ... now, I dunno what part you missed ... but that's JavaScript, and I'm 
working in PHP ... why would I care what's been done in JS ??? That won't 
get me much further with what I'm trying to do...

Not to mention that I hate using others code, and never have sofar, then it 
will take about as long to convert that to something workable in PHP, as it 
will figuring out how to do it in PHP

Rene

At 14:15 30-03-2004, you wrote:
Already been done:

http://www.destroydrop.com/javascripts/tree/

Mark
--
Rene Brehmer
aka Metalbunny
~ If you don't like what I have to say ... don't read it ~

http://metalbunny.net/
References, tools, and other useful stuff...
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Tree structure - how to show only current branch ??

2004-03-30 Thread Ignatius Reilly
The same can be achieved by using the excellent PEAR HTML_TreeMenu class.
Key advantage, of course, is that the API is in PHP.

HTH
Ignatius
_
- Original Message - 
From: Paul Miller [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, March 30, 2004 4:22 PM
Subject: RE: [PHP-DB] Tree structure - how to show only current branch ??


 Ya it has - that is a great script!
 
 -Original Message-
 From: Galbreath, Mark A [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, March 30, 2004 7:15 AM
 To: '-{ Rene Brehmer }-'; '[EMAIL PROTECTED]'
 Subject: RE: [PHP-DB] Tree structure - how to show only current branch
 ??
 
 
 Already been done:
 
 http://www.destroydrop.com/javascripts/tree/
 
 Mark
 
 -Original Message-
 From: -{ Rene Brehmer }- [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, March 30, 2004 7:50 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] Tree structure - how to show only current branch ??
 
 
 Ok, Tom Reed got my thinker running big time ... and I've been trying to
 
 build an expandable and modifiable tree structure where it only displays
 
 the branch leading to the current folder... Showing the entire tree is 
 easy, but how do I change the code to only display the branch we need???
 
 ... I've never coded visual trees before, so this is new for me ...
 
 Found several samples with google where the code relies on the structure
 
 being fixed in the DB. What I want to create is the possibility to mode 
 folders around within the tree ... literally moving branches from one
 place 
 to another, while retaining their content.
 
 DB structure is simply this (I want to get rid of the level field if
 it's 
 at all possible to count the levels with recursive functions, but for
 now 
 it stays).
 
   folderID int(10) UNSIGNED auto-increment
   parentID  int(10) UNSIGNED
   level  tinyint(3) UNSIGNED
   name  varchar(255)
 
 (I'm fully aware that int may be overkill, but this is for testing
 purposes...)
 
 test data:
 http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree
 +tes
 ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepe
 at_c
 ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++
 ORDE
 R+BY+%60folderID%60+ASCfolderID
 http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree
 +tes
 ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepe
 at_c
 ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++
 ORDE
 R+BY+%60parentID%60+ASCparentID
 http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree
 +tes
 ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepe
 at_c
 ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++
 ORDE
 R+BY+%60level%60+ASClevel
 http://localhost/phpmyadmin/sql.php?lang=en-iso-8859-1server=1db=tree
 +tes
 ttable=folderspos=0session_max_rows=30disp_direction=horizontalrepe
 at_c
 ells=100dontlimitchars=0sql_query=SELECT++%2A+%0AFROM++%60folders%60++
 ORDE
 R+BY+%60name%60+ASCname
 
 1 0 0 parent 1
 2 0 0 parent 2
 3 0 0 parent 3
 4 0 0 parent 4
 5 0 0 parent 5
 6 1 1 child of 1
 7 3 1 child of 3
 8 1 1 child 2 of 1
 9 6 2 sub-child 1
 10 6 2 sub-child 2
 11 10 4 sub-sub 1
 12 10 4 sub-sub 2
 13 11 5 sub-sub-sub 1
 
 Current code looks like this, the 2 subfunctions prints the branches,
 the 
 main function below prints the root structure...:
 
 function count_children($parentID) {
 // count number of children in folder
$count = mysql_query(SELECT COUNT(*) AS num_children FROM folders
 WHERE 
 `parentID`='$parentID');
$numrows = mysql_fetch_array($count);
 
return $numrows['num_children'];
 }
 
 function print_children($parentID) {
 // print the branch of sub-folders
$children = mysql_query(SELECT folderID,level,name FROM folders
 WHERE 
 `parentID`='$parentID');
 
while($child = mysql_fetch_array($children)) {
  $folderID = $child['folderID'];
  $name = $child['name'];
  $level = $child['level'];
 
  for ($i = 0; $i  $level; $i++) {
echo('middot');
  }
  echo(middot; a
 href=\test1.php?folderID=$folderID\$name/abr\n);
 
  // let's find children... recursive call !!
  if (count_children($folderID)  0) {
print_children($folderID);
  }
}
 }
 
 // get root parents -- main tree function
 $parents = mysql_query(SELECT folderID,name FROM folders WHERE 
 `parentID`='0');
 
 while($folder = mysql_fetch_array($parents)) {
$folderID = $folder['folderID'];
$name = $folder['name'];
 
echo(middot; a
 href=\test1.php?folderID=$folderID\$name/abr\n);
 
// let's find children...
if (count_children($folderID)  0) {
  print_children($folderID);
 
}
 }
 
 
 The output of all this looks like this:
 
 . http://localhost/tests/tree%20structure/test1.php?folderID=1parent 1
 .. http://localhost/tests/tree%20structure/test1.php?folderID=6child
 of 1 ...
 http://localhost/tests/tree%20structure/test1.php?folderID=9sub-child
 1
 ...
 http

Re: [PHP-DB] Tree structure - how to show only current branch ??

2004-03-30 Thread Ricardo Lopes
 Not to mention that I hate using others code

i dont agrre with that, i guess probably you write your own string/date
handling functions, you write your own code to connect to database and other
stuffs right? :-)

 it will take about as long to convert that to something workable in PHP,
as it
 will figuring out how to do it in PHP

the code is good, and is very easy to integrate it with PHP and with your
table, you have all the data that is needed, the idea is not to port the
code to php. Probably you didnt read the script documentation.

If you don't want to use javascript for some reason like your browser
doesn't support it (ex: lynx :-) ) or because you want to do a only
server-side implementation that would only be usefull if you have a really
big node list, in that case the php only version would be better or if you
want a static tree menu.

The PEAR::HTML_TreeMenu can be coded entirely in php but uses javascript to
expand/contract the menus, this is transparent to the programmer, but uses
javascript anyway.


- Original Message -
From: -{ Rene Brehmer }- [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, March 30, 2004 4:32 PM
Subject: RE: [PHP-DB] Tree structure - how to show only current branch ??


 Eh ... now, I dunno what part you missed ... but that's JavaScript, and
I'm
 working in PHP ... why would I care what's been done in JS ??? That won't
 get me much further with what I'm trying to do...

 Not to mention that I hate using others code, and never have sofar, then
it
 will take about as long to convert that to something workable in PHP, as
it
 will figuring out how to do it in PHP


 Rene

 At 14:15 30-03-2004, you wrote:
 Already been done:
 
 http://www.destroydrop.com/javascripts/tree/
 
 Mark

 --
 Rene Brehmer
 aka Metalbunny

 ~ If you don't like what I have to say ... don't read it ~

 http://metalbunny.net/
 References, tools, and other useful stuff...

 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php