Results 1 to 10 of 10

Thread: [RESOLVED] Get Parent Folders - Database

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Resolved [RESOLVED] Get Parent Folders - Database

    Ok, i have a file manager page, and i created a 'move files' page.

    This page lists all of the members folders from the database.

    Here is the DB structure:
    Code:
    folderID | parentID | memberID | folder_name | password | sharesetting
    1 | 0 | 2 | Test Folder | NULL | 0
    2 | 1 | 2 | Test Child Folder | NULL | 0
    3 | 1 | 2 | Test Child Folder numeo 2 | NULL | 0
    So according to that database, folder 1 is a parent folder shown at ROOT. Folders 2 & 3 are child folders of 1.

    What i want to do, is have it so that when it lists all of the members folders it will show it as a Path. EG:

    Test Folder
    Test Folder / Test Child Folder
    Test Folder / Test Child Folder numero 2

    But it is not going to be limited to 2 folders. it could be a lot more than that.
    My usual boring signature: Something

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Get Parent Folders - Database

    Keep getting the parent of your current page (loop), until you get a parent id of 0 (you should use NULL as a value and add foreign keys).


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Get Parent Folders - Database

    here is my loop:

    PHP Code:
    <?php
    $sql 
    "SELECT * FROM `folders` WHERE memberID='{$_SESSION['member_id']}'";
                
    $query mysql_query($sql);
                
    ?>
                <h2>Mass Move Files</h2>
                Where do you want to move these files?<br>
                <form action='index.php?do=movedelete&move=1' method='POST'>
                    <input type="hidden" value='<?php print_r($_POST['checkfiles']); ?>' name='checkfiles'>
                    <select name='moveto'>
                        <?php while($row mysql_fetch_array($query)){    ?>
                            <option value='<?php echo $row['folderID']; ?>'><?php echo $row['folder_name']; ?></option>
                        <?php ?>
                    </select>
                    <input type='submit' name='submit' value='Move Files!'>
                </form>
                <?php
    I dont understand what you mean keep getting them.
    My usual boring signature: Something

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Get Parent Folders - Database

    To print the path I guess it would be something like this (not tested) :

    PHP Code:
    $sql "SELECT * FROM `folders` WHERE memberID='".$_SESSION['member_id']."'";
    $result mysql_query($sql);
    $row mysql_fetch_assoc($result);

    $path $row['folder_name'];

    $parent_id $row['parentID'];
    while (
    $parent_id != 0)
    {
     
    $sql_parent "SELECT * from `folders` where `parentID` = '".$parent_id."'";
     
    $result_parent mysql_query($sql_parent);
     
    $row_parent mysql_fetch_assoc($result_parent);

     
    $parent_id $row_parent['parentID'];
     
     
    $path $row_parent['folder_name'].' / '.$path;

    I'm sure it doesn't work, but hopefully you get the idea


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Get Parent Folders - Database

    your code is confusing the hell outta me. I have been looking at it for the past 10 minutes trying to figure out how to make it work, and i have no idea what i am doing.

    Also, can you use [php] [/php] not [HIGHLIGHT=php] [/highlight]
    My usual boring signature: Something

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Get Parent Folders - Database

    So I'll assume it's not working?

    Can you post an sql dump for that table? Maybe i can try a bit more? Maybe even test it this time?


    Has someone helped you? Then you can Rate their helpful post.

  7. #7

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Get Parent Folders - Database

    attached... saved as .txt for upload compatibility

    go online
    Last edited by dclamp; Apr 4th, 2008 at 01:47 PM.
    My usual boring signature: Something

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Get Parent Folders - Database

    OK, try and analyze this now

    PHP Code:
    <?php
    $sql 
    "SELECT * FROM `folders` WHERE `memberID`='".$_GET['member_id']."' and `folderID` = '".$_GET['folder_id']."'";
    $result mysql_query($sql) or die($sql);
    $row mysql_fetch_assoc($result);

    $path $row['folder_name'];

    $parent_id $row['parentID'];

    while (
    $parent_id != 0) {
        
    $sql_parent "SELECT * from `folders` where `folderID` = '".$parent_id."'";
        
    $result_parent mysql_query($sql_parent);
        
    $row_parent mysql_fetch_assoc($result_parent);
        
        
    $parent_id $row_parent['parentID'];
        
        
    $path $row_parent['folder_name'].' / '.$path;    


    echo 
    $path;
    This was the link I used : http://localhost/dylan.php?member_id=2&folder_id=5

    I don't know what member ID is for.


    Has someone helped you? Then you can Rate their helpful post.

  9. #9

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Get Parent Folders - Database

    got it to work. with a little modification, it works great

    PHP Code:
    <?php
    $sql 
    "SELECT * FROM `folders` WHERE `memberID`='".$_GET['member_id']."'";
    $result mysql_query($sql) or die($sql);
    while(
    $row mysql_fetch_assoc($result)) {

        
    $path $row['folder_name'];

        
    $parent_id $row['parentID'];

        while (
    $parent_id != 0) {
            
    $sql_parent "SELECT * from `folders` where `folderID` = '".$parent_id."'";
            
    $result_parent mysql_query($sql_parent);
            
    $row_parent mysql_fetch_assoc($result_parent);
            
            
    $parent_id $row_parent['parentID'];
            
            
    $path $row_parent['folder_name'].' / '.$path;    
        }

        echo 
    "Path: ".$path"<br>";
    }
    My usual boring signature: Something

  10. #10
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [RESOLVED] Get Parent Folders - Database

    Ah, to print the path for all the folders of a member? I suppose that's what you're doing... Glad you got it working


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

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



Click Here to Expand Forum to Full Width