Forum OpenACS Development: To display tree Hierarichy with the following condition

we have a hierarichy as

1
--> 2
-->4
-->5
--> 3
--> 6
--> 7

table has
id parentid
1 0
2 1
3 1
4 2
5 2
6 3
7 3

if we give the input as 2
we should get the
display as
1
--> 2
--> 4
--> 5
i.e one level up ,the level and the child level values

similarly if we give 4 as input
the requierd output should be
2
--> 4

and if the input is 3 then
1
--> 3
-->6
-->7

Sujjest the syntax to form this query .

sujjest the syntax
select
 id,
 parent_id
from
 my_hierarchy_table
where
 id = :myid
or
 parent_id = :myid
order by
 id,
 parent_id;

But this assumes that id is always less than parent_id, and that the ordering should follow the order of input of the rows. Overall, not a great strategy for creating a hierarchy.

but i want something like this

GRP1
GRP2
GRP4
GRP5

using recursion

Recursion is a procedural language concept. This is the wrong forum for this type of question. You have also not stated a question which requires recursion.

proc group_recurse { list } {
  if {[llength $list] > 1} {
    return "GRP[lindex $list 0]\n[group_recurse [lrange $list 1 end]]"
  } else {
    return "GRP[lindex $list 0]\n"
  }
}

puts [group_recurse {1 2 4 5}]