1

これを回避できる方法はありますか(データベース内のディレクトリデータをループし、すべての子と子の子に対して同じデータを取得します...無限:

$directories = DB::queryOneColumn('id', "SELECT `id` FROM `data` WHERE `level` = '1' AND `batch` = %s", $lastBatchID);
foreach ($directories as $dir) {

$dirInfo = DB::query("SELECT `folder`, `size` FROM `data` WHERE `id` = $dir");
$size = intval($dirInfo[0]['size']) * 1024;
echo stripslashes($dirInfo[0]['folder']) . "  -Current:" . human_filesize($size) . "<br>";


$directories2 = DB::queryOneColumn('id', "SELECT `id` FROM `data` WHERE `parentID` = %s AND `batch` = %s", $dir, $lastBatchID);

foreach ($directories2 as $dir2) {

    $dirInfo = DB::query("SELECT `folder`, `size` FROM `data` WHERE `id` = $dir2");
    $size = intval($dirInfo[0]['size']) * 1024;
    echo "=>" . stripslashes($dirInfo[0]['folder']) . "  -Current:" . human_filesize($size) . "<br>";


    $directories3 = DB::queryOneColumn('id', "SELECT `id` FROM `data` WHERE `parentID` = %s AND `batch` = %s", $dir2, $lastBatchID);

    foreach ($directories3 as $dir3) {

        $dirInfo = DB::query("SELECT `folder`, `size` FROM `data` WHERE `id` = $dir3");
        $size = intval($dirInfo[0]['size']) * 1024;
        echo "=>=>" . stripslashes($dirInfo[0]['folder']) . "  -Current:" . human_filesize($size) . "<br>";


        $directories4 = DB::queryOneColumn('id', "SELECT `id` FROM `data` WHERE `parentID` = %s AND `batch` = %s", $dir3, $lastBatchID);

        foreach ($directories4 as $dir4) {

            $dirInfo = DB::query("SELECT `folder`, `size` FROM `data` WHERE `id` = $dir4");
            $size = intval($dirInfo[0]['size']) * 1024;
            echo "=>=>=>" . stripslashes($dirInfo[0]['folder']) . "  -Current:" . human_filesize($size) . "<br>";

            $directories5 = DB::queryOneColumn('id', "SELECT `id` FROM `data` WHERE `parentID` = %s AND `batch` = %s", $dir4, $lastBatchID);

            foreach ($directories5 as $dir5) {

                $dirInfo = DB::query("SELECT `folder`, `size` FROM `data` WHERE `id` = $dir5");
                $size = intval($dirInfo[0]['size']) * 1024;
                echo "=>=>=>=>" . stripslashes($dirInfo[0]['folder']) . "  -Current:" . human_filesize($size) . "<br>";
            }
        }
    }
}

}

基本的に、ディレクトリの x レベルのデータを取得しており、次のようにデータを表示するには各レベルのループが必要です。

C:\it\AD-Chris Integration -Current:49.70M
=>C:\it\AD-Chris Integration\AD-Chris2 -Current:49.69M
=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris -Current:5.22M
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\Common -Current:599.00K
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\Department -Current:453.00K
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\Encrypt -Current:327.00K
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\Location -Current:387.00K
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\Manager -Current:1.36M
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\ScanForStaffID -Current:348.00K
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\Title -Current:498.00K
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\bin -Current:529.00K
=>=>=>C:\it\AD-Chris Integration\AD-Chris2\AD-Chris\obj -Current:439.00K
=>=>C:\it\AD-Chris Integration\AD-Chris2\_Deploy -Current:622.00K

必要な深さのレベル数を持つ変数が利用可能です

4

1 に答える 1

3
function something($dir, $lastBatchID, $level = 0) {
    $dirInfo = DB::query("SELECT `folder`, `size` FROM `data` WHERE `id` = $dir");
    $size = intval($dirInfo[0]['size']) * 1024;

    echo str_repeat('=>', $level);
    echo stripslashes($dirInfo[0]['folder']) . "  -Current:" . human_filesize($size) . "<br>";

    $directories2 = DB::queryOneColumn('id', "SELECT `id` FROM `data` WHERE `parentID` = %s AND `batch` = %s", $dir, $lastBatchID);

    if ($level > 5) return;

    foreach ($directories2 as $dir2) {
        something($dir2, $lastBatchID, $level + 1);
    }
}

$directories = DB::queryOneColumn('id', "SELECT `id` FROM `data` WHERE `level` = '1' AND `batch` = %s", $lastBatchID);
foreach ($directories as $dir) {
    something($dir, $lastBatchID);
}
于 2013-01-27T23:11:44.010 に答える