Jump to content

PHP - Dyanamic Virtual Folder Listing help


Cheeky Chino

Recommended Posts

Hi Guys,

I have a script to create virtual folders to organise some files, you can create head folder, and branch down sub folders as much as you want.

My database is like:

FolderID - Name - SubFolder
1 - Folder 1 - 0
2 - Folder 2 - 1
3 - Folder 3 - 1
4 - Folder 4 - 3
5 - Folder 5 - 0

What i want is to have that dynamically pulled out and displayed as such

Folder 1
-- Folder 2
-- Folder 3
----Folder 4
Folder 5

What i've tried so far that came close to working is the following code, but it's all not in order :(.

[CODE]// Create list of available folders to put this new one in
$sql = mysql_query("SELECT * FROM sg_folders ORDER BY FolderID, SubFolder");

while ($row = mysql_fetch_array($sql))
{
$folderid = $row['FolderID'];
$foldername = $row['Name'];
$subfolder = $row['SubFolder'];
$indent = 0;

while($subfolder)
{
$indent ++;

$sql2 = mysql_query("SELECT * FROM sg_folders WHERE FolderID = ".$subfolder);

if (mysql_num_rows($sql))
{
while ($row2 = mysql_fetch_array($sql2))
$subfolder = $row2['SubFolder'];
}
else
$subfolder = '';
}

$i = 0;
$pretext = '';

while ($i <= $indent)
{
$i ++;
$pretext .= "--";
}

$folders .= "<option value='".$folderid."'>".$pretext." ".$foldername."</option>";
}
[/CODE]

Could anyone help or let me know how to approach it, i've tried a few things and simply cant figure it out.

Chino
Link to comment
https://forums.phpfreaks.com/topic/36280-php-dyanamic-virtual-folder-listing-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.