...

View Full Version : Grandpa tree



sasha85
10-14-2007, 01:20 PM
imagen old and nice grandpa he got 5 sons and 4 daughters
(4+5=9)
every one of the sons got 5 sons
(5x5=25)
and every one of the daughters got 2 sons and 2 daygters
(2+2=4)
(4x4=16)
that means the granpa got 16+25=41 grandchildren...

=>on the 1(first) level he got 9people
=>on the 2(second) level he got 41people

and may be some of the children got sons or daughters too...in that case he will got a 3(third) level too...


in my asp files, there are no replay of names=every body got his original name wich no one esle have.
i enter to the database :
"first name" "fathers name"

i need to build some circulation function that counts how much levels granpa have and how much people he got on every level.

someone wrote/saw something like this before?
any help will help right now:)

:D

Whatever Jr.
10-15-2007, 08:43 AM
Google for 'recursive'

HTH, Tom

sasha85
10-16-2007, 12:05 PM
i found no such way of display on the net...


dim level
sub GetTree(code)


dim mySQL, conntemp1, rst1
mySQL1="SELECT * FROM mag WHERE father='" & code & "'"
call getFromDatabase(mySQL1, rst1, "ciss.asp")


if ((not rst1.EOF) and (not rst1.BOF)) then

while not rst1.EOF

for cc=1 to level
Response.Write "&nbsp"
Response.Write "&nbsp"
next

Response.Write rst1("Name")
Response.Write "<br>"
level = level + 1
GetTree(rst1("code"))
level = level - 1

rst1.movenext
wend
end if

Set rst1 = Nothing
end sub





level = 1


dim vab, mySQL, conntemp, rst
vab="grand"
mySQL="SELECT * FROM mag WHERE code='" & vab & "'"
call getFromDatabase(mySQL, rst, "citttss.asp")



rst.movefirst

level=0
while not rst.EOF

for cc=1 to level
Response.Write "&nbsp"
Response.Write "&nbsp"
next

Response.Write rst("Name")
Response.Write "<br>"

level=level+1
GetTree(rst("code"))
level=level-1

rst.movenext

wend

*all the code fileds are letters codes...that's why i using '" & vab & "'"

well, this shows all the rows...but in one column...
how can i make this structure?



A
| |
B C
/\
D E

sasha85
10-16-2007, 03:13 PM
any structure that will be understood any level of the tree...cause i now understand that what i draw is so difficult to write...:(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum