SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to sort these records?

    Hi! I am building a file/folder tree. I have

    id, name, parentid, foldertype;
    1, root, 0, 1;
    2, folderA, 1, 1;
    3, folderB, 1, 1;
    4, fileA, 2, 0;
    5, fileB, 2, 0;

    Foldertype =1 is folder, 0 is file. Because fileA and fileB belongs to folderA which is parentid = 2, I want to have it appear immediately after folder A. ie. I want to have something like this:

    1, root, 0, 1;
    2, folderA, 1, 1;
    4, fileA, 2, 0;
    5, fileB, 2, 0;
    3, folderB, 1, 1;

    Is it possible? How? Thanks.

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    imho I think you will be much better off in the long run if you use the nested set model rather than the adjacency list model you are currently using - but that's just me.

    the above link has the scripts which should help for both models.

    if some time down the track you will want to move nodes and all their children to a new node I have some scripts posted in this thread which could help if you use the nested set model.

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,044
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    What you are trying to achieve should be handled in the application language not SQL.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks.


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
  •