I have navigation folders structure stored in mysql:
I have this navigation:
Now I need to make automatic detect parent's folders and create navigation information bar for all levels parent-folders but I dont know how, I have only first level parent.
How I can create loop and stop automatically when parent is 0?
Here is my function:
public static function Gallery($fid = NULL){
$folder_id = $fid ? $fid : 1;
echo "<div class=\"gallery-c\">";
echo "<div class=\"gallery-path--c\">";
$current_path_obj = Database::dbquery("SELECT * FROM calendar_gallery_folders WHERE id = $fid", false, true)['result'][0];
$current_path_name = $current_path_obj->folder;
$current_path_parent = $current_path_obj->parent;
$parent_path_name = Database::dbquery("SELECT folder FROM calendar_gallery_folders WHERE id = $current_path_parent", false, true)['result'][0]->folder;
// Navigation information bar
echo $parent_path_name."/".$current_path_name;
echo "</div>";
echo "<div class=\"gallery-folder--c\">";
// Folders
foreach(Database::dbquery("SELECT * FROM calendar_gallery_folders WHERE parent = $folder_id ORDER BY id", false, true)['result'] as $folder){
echo "<a class=\"js-gallery-folderlink gallery-folder--box\" data-folder=\"$folder->id\">
<div class=\"gallery-folder--icon\"><span class=\"icon material-symbols-outlined\">folder</span></div>
<div class=\"gallery-folder--text\">$folder->folder</div></a>";
}
echo "</div>";
echo "</div>";
}


