I have a database-driven system of files and folders with permission to view these contents specified on a per-user basis. Occasionally this means assigning a folder a new parent folder if the user is blocked from seeing it. I've provided a visual aid that makes this much easier to comprehend:

So here in this example we would be looking to assign "TEST2" as the parent of "INSIDE 4". To do this, I have a recursive function that finds the new parent ID that should be assigned. It looks like this:
Code: Select all
function findParentID($userID, $folderID) {
global $DB;
$SQL = "SELECT folderID FROM navAccessFolders WHERE folderID=".$folderID." AND userID=".$userID;
$Row = $DB->GetRow($SQL);
if ($Row) {
echo "value to return: ".$folderID."<br>"; // for troubleshooting
return $folderID;
} else {
$SQL = "SELECT parentID FROM folders WHERE folderID=".$folderID;
$Row = $DB->GetRow($SQL);
findParentID($userID, $Row["parentID"]);
}
}Code: Select all
$parentID = findParentID(1, 138); // using "1" as a sample user ID
echo "value returned: ".$parentID."<br>"; // for troubleshootingCode: Select all
value to return: 135
value returned:If someone can figure this one out, you will have made my list of all-time top coders (and maybe we can hire you for some work sometime??). Any advice or help is much appreciated. I'm so close...