I have built a hierarchical file structure using php/mysql. There are two tables, one holding the folders (a unique id, a label and the id of their parent folder) and another table holding the contents of the folders linked via the unique folder id. As i navigate through these folders i'd like to build a breadcrumb trail but i'm not too sure the best way of doing this. There is no actual file structure to reflect as all files are in the same folder.
This is the snippet of code that displays the folders:
<?php
# viewfolders
case 'viewfolder':
# get id of selected folder and its parent folder
$cpf_id = $_GET['cpf_id'];
$sql = "SELECT * FROM `scc_public_folders` WHERE `cpf_parent_id` = '$cpf_id'";
$dosql = mysql_query($sql) or die(mysql_error());
if($cpf_id == 0)
{
echo '
<a href="materials.php"><div style="margin:0px; padding:0px;"><img src="images/icons/folder_back.gif" width="51" height="53" border="0"></div></a>
';
}
else
{
echo '
<a href="moveup.php?cpf_id='.$cpf_id.'"><div style="margin:0px; padding:0px;"><img src="images/icons/folder_back.gif" width="51" height="53" border="0"></div></a>
';
}
echo '
<ul class="folders">
';
while($folder = mysql_fetch_array($dosql))
{
?>
<a href="materials.php?mode=viewfolder&cpf_id=<?php echo $folder['cpf_id']; ?>"><li><?php echo $folder['cpf_label'];?></li></a>
<?php
}
public_folder_contents($_GET['cpf_id']);
echo '
</ul>
';
break;
and when moving back up the structure:
$cpf_id = $_GET['cpf_id'];
$doesql = mysql_query("SELECT `cpf_parent_id` FROM `scc_public_folders` WHERE `cpf_id` = '$cpf_id'") or die (mysql_error());
$res = mysql_result($doesql, 0);
header("location: materials.php?mode=viewfolder&cpf_id=".$res."");
I reckon the best way to achieve this would be to track back to the parent folder using the cpf_id that is called from the query string so i suppose the question is how can i loop through from a specific id and display the parent_id's and parent_labels one by one until the parent_id = 0 ?