Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Grandpa tree

  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Grandpa tree

    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

    Last edited by sasha85; 10-14-2007 at 01:24 PM.
    By the time u recognize this moment, This moment will be gone.

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Posts
    120
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Google for 'recursive'

    HTH, Tom

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    well that's what i wrote:

    i found no such way of display on the net...
    Code:
    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

    Last edited by sasha85; 10-16-2007 at 01:37 PM.
    By the time u recognize this moment, This moment will be gone.

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    179
    Thanks
    4
    Thanked 0 Times in 0 Posts

    you know what...

    any structure that will be understood any level of the tree...cause i now understand that what i draw is so difficult to write...
    By the time u recognize this moment, This moment will be gone.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •