SitePoint Sponsor

User Tag List

Results 1 to 25 of 141

Hybrid View

  1. #1
    ********* Articles ArticleBot's Avatar
    Join Date
    Apr 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Article Discussion

    This is an article discussion thread for discussing the SitePoint article, "Storing Hierarchical Data in a Database"

  2. #2
    SitePoint Enthusiast ryushe's Avatar
    Join Date
    Aug 2004
    Location
    NL
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, 'm using the first version at this moment as I have a many-to-many relation in my DB. So my question might be a bit stupid, but can anyone explain to me how I can have the first level horizontal, and the second layer under that one (also horizontal), etc etc?
    Also how to make a visual indicator (link color change) which item is active?

  3. #3
    SitePoint Zealot David C's Avatar
    Join Date
    Nov 2003
    Location
    New York!
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean horizontal in the sense of presentation? If so, the DB query probably wouldn't change, it would be done with HTML/CSS.

  4. #4
    SitePoint Enthusiast ryushe's Avatar
    Join Date
    Aug 2004
    Location
    NL
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, presentation wise. Problem is, the main "browser" I'm creating this for does not (yet) understand CSS, and at most basic html tags, although no table tags yet.
    I "need" something like:

    parent1 | parent2 | parent3
    child 1 | child 2 | child 3 | child 4
    subchild 1 | subchild 2

    I've been playing around with creative < b r / > placements, but no luck yet. Only option I see is to make a duplicate function which is triggered by a var passed onto it to activate sublevel. Of course this should be able to be done without creating extra functions I'd say. Any suggestions?

  5. #5
    Non-Member Big Fat Bob's Avatar
    Join Date
    Sep 2004
    Location
    United Kingdom (Come)
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yo

    You might find this thread interesting then

    http://www.sitepoint.com/forums/showthread.php?t=186601

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    XML does have it's uses, though in your point you could query the XML with XPATH though you'd be limited to that given data within the XML file, whereas you couldn't (easily) query the data in one XML file against another one, suchas product catelog and products.

    Two seperate though interwinded entities that is where the database has the upperhand... relational data in other words.

    On your last question, XML is a great technology... For distribution but not for performing queries. There are a number of XML databases out there, but I cannot see any benifit of using one over a relational database if all your going to do is to perform lookups/queries

  7. #7
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there really a need of left and right value?
    Why do we need the left and right?
    Isn't just the parent sufficient?

  8. #8
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am asking because RDLDB [doc] is hierarchy-related. And I have never felt the need of having right or left and still have never been wondering which child comes first. The first in is the first out (The first child is first, the second is second, the third is third, etc).
    That is why I was wondering why would anyone use right and left. And why would anyone need so many computations.

  9. #9
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Btw, one could also have a look at pear's nested set class...

  10. #10
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Does somebody know how to get next result:

    (I am using same tree as in article):

    For example, I wand to target only "Cherry" node;

    Code:
    Food
    --Fruit
    ----Red
    -------Cherry
    ----Yellow
    ----..more Fruit
    --Meat
    --...more Food
    As can be seen here, I want to display only "Cherry" subtree in complete, and other leafs only in start. If some code need to be added in PHP, this will help too.

    regards

    Thanks in advance!

  11. #11
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Retrieve correct node with node values are not unique

    To retrieve single path to 'banana' you would use the following query
    Code:
    SELECT p.title
    FROM tree1 AS node,
    tree1 AS p
    WHERE node.lft BETWEEN p.lft AND p.rgt
    AND node.title = 'banana'
    ORDER BY p.lft;
    however this won't work if we had 'banana' in more than one node.
    If the values of all nodes from one of the bananas were known can the right 'banana' be found with one query?

  12. #12
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling function from a Store Procedure

    what if a store procedure is created to call the items from the database. How would you update the code to display this information in the correct order on the webpage?

    I am creating something similar but using ASP and vbscript and I'm having a difficult time getting the data to display correctly. right now it's display all the items as parents. Any suggestions?

  13. #13
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had a problem like this awhile ago.

    Here's my solution:
    http://geniegate.com/art/pdf/tree-st...l-database.pdf

    It was kind of nice to be able to do this:

    Code:
    SELECT 
      * 
    FROM 
      directory 
    WHERE 
      lookup_directory_ancestor_path(id) LIKE 'Blah/%';
    And not clutter the program up with a bunch of tree handling stuff.

    I was going to go with flat files at first, but decided I wanted relational after thinking about some of the other aspects (integrity checks).

    You can also create database-side indexes, but in practice, I haven't needed them. (I just created an index, then dropped it, to see if it'd actually work.)

  14. #14
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how can i find the level?

  15. #15
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by tudoroiuj View Post
    how can i find the level?
    which level?

    please show your table design
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  16. #16
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tudoroiuj View Post
    how can i find the level?
    My apologies if this has already been suggested earlier, but this thread is too long for me to go back looking through all the posts.

    To store hierarchial data in a database I would recommend using The Nested Set Model. This link also has some very useful sql scripts on extracting hierarchy information from the database.

    I have posted some sql scripts on how to move hierarchial nodes.


Bookmarks

Posting Permissions

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