tree creation

Discussion in 'PHP' started by gaurav_, Sep 17, 2011.

  1. #1
    hi,
    i have come across in the need of the code written on the URL below

    
    http://snipplr.com/view/22864
    
    Code (markup):
    i can integrate this code to my database and it works only for this query

    
    SELECT * FROM users
    
    Code (markup):
    it means it displays the tree of the Top Most Root only, But i don't have any idea what should be the sql query if i want to display the tree of a desired user in the database. :-(

    please help me.

    my table is

    users

    columns are
    id
    name
    my_node_id
    my_root_id
    my_left_node
    my_right_node
     
    gaurav_, Sep 17, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Do you have the variables at the top of tree_example() filled with the proper data? The code shown prints a tree for the data shown in the $rows[] array, not the data from your database.
     
    Rukbat, Sep 18, 2011 IP
  3. gaurav_

    gaurav_ Member

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Yes you are right,
    but i want to know, what to do if i want to use this code with my database?
     
    gaurav_, Sep 18, 2011 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    You read the database into an array named $rows[], structured the same way as the array in the example code. And comment out the part of the code that loads the $rows[] array (lines 19-27).
     
    Rukbat, Sep 18, 2011 IP
  5. gaurav_

    gaurav_ Member

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Hi Rukbat,
    yes you are right, But this code need some modification to get it done for any node in the database. But this code words only for the first node in the database and does not work for any other node.

    that 19 to 27 can be get by using
    
    $result = mysql_fetch_array($sql,MYSQL_ASSOC);
    
    Code (markup):
    but the problem is it does not displays desired user's tree, it only displays the first user's tree, Thats y this code need modification or need a good sql query that can overcome this problem :-|

    can i share more info with you for this problem?
     
    gaurav_, Sep 18, 2011 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    You do the select for the desired user's data, not for the first user's data. The code you linked to is only the tree display, not the method of getting the data to display. If you want all of it in one package, try http://dhtmlx.com/docs/products/dhtmlxTree/index.shtml The free version should be more than enough for what you need.
     
    Rukbat, Sep 19, 2011 IP
  7. gaurav_

    gaurav_ Member

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Hi Rukbat,
    thanks for you help,
    yes you are right, But for the above QUOTE text, i don't know how can i get the desired nodes from the SQL query, Could you please help me with the SQL query that only fetch only the desired data?

    OR

    i can get all the desired data via traversal and put it into array, So we will have all the desired data into an array.

    i also tried this but, that script go to infinite loop :-(

    thanks for the link for integration of tree, but i have to get all the data from database. So first we have to get the proper and correct tree display on the page and then we can integrate it with the DHTML treeview

    thank you
     
    gaurav_, Sep 19, 2011 IP