我正在製作一個文件管理器系統我將所有文件夾名稱和文件存儲在數據庫中(MySQL)我試圖在數據庫中添加文件夾,然後向它們添加子文件夾,我想它顯示所有文件夾中有正確的 的位置來展示,這裏是一個如:在php&mySQL中創建文件目錄
Folder1
Folder1-Sub1
Folder1-Sub1-Sub1
Folder1-Sub1-Sub2
Folder1-Sub1-ect...
Folder1-Sub2
Folder1-Sub3
Folder1-ect...
Folder2
Folder2-Sub1
Folder2-sub2
ect...
我目前擁有的MySQL表奠定了這樣
id folder_name sub_folder_id file_name file_folder_id
1 Folder1 -1 -1 -1
2 Folder1-Sub1 1 -1 -1
3 Folder1-Sub1-Sub1 2 -1 -1
4 Folder1-Sub1-Sub2 2 -1 -1
5 Folder1-Sub2 1 -1 -1
6 Folder1-Sub3 1 -1 -1
7 Folder2 -1 -1 -1
8 Folder2-Sub1 7 -1 -1
9 Folder2-Sub2 7 -1 -1
這裏是以下代碼,我到目前爲止
$GetFolders = mysql_query("SELECT * FROM user_filesfolders");
$file_tree = "";
while($ShowFolders = mysql_fetch_array($GetFolders))
{
if($ShowFolders['folder_name']==-1){
//Dont Add Becuse it not a folder
}else{
$file_tree .= '
<tr>
<td height="30" colspan="4"><strong>
<input type="checkbox" name="checkbox[]" class="folder_checkbox" id="-1" />
<span class="tree_drop" id="-1">
<img src="images/Folder.png" width="15" height="21" /> <span id="status">+</span> '.$ShowFolders['folder_name'].'</strong>
</span>
</td>
</tr> ';
//I need to keep adding floders to folder from mysql
$file_tree .= '
<tr>
<td height="30" colspan="4"><strong>
<input type="checkbox" name="checkbox[]" class="folder_checkbox" id="-1" />
<span class="tree_drop" id="-1">
<img src="images/Folder.png" width="15" height="21" /> <span id="status">+</span> '.$ShowFolders['folder_name'].'</strong>
</span>
</td>
</tr> ';
}
}
}
有人可以幫我請,或導致我正確的道路
什麼不行?這只是一個關於格式化HTML的問題,還是你有其他問題? – kijin 2010-10-30 06:45:26
此刻我正在獲取文件夾什麼是不是一個子文件夾,然後我想從子文件夾從MySQL相同的表添加到正確的文件夾,我想做的是爲表中的所有子文件夾所以把子子文件夾中的文件夾 – Rickstar 2010-10-30 06:51:19
在mysql架構中,sub_folder_id列實際上包含對PARENT文件夾的引用。列名混淆了一點:) – Kel 2010-10-30 06:53:41