0

据我所知,我无法将其正确放入表结构中,但所有编码都是正确的,但由于某种原因它无法正常工作。

这是我的代码:

<?php
    echo "<table class='array'>
        <tr><th>&nbsp;&nbsp; Employee &nbsp;&nbsp;&nbsp;</th>
        <th>In Que &nbsp;&nbsp;&nbsp;</th>
        <th>Incomplete &nbsp;&nbsp;&nbsp;</th>
        <th>Processed </th></tr>";
    $count_result=array();
    $path = "Users";
    $folders = @scandir("$path");
    if ($folders) {
        foreach ($folders as $item) {
            $count = 0;
            if ((substr($item, 0, 1) == '.') || (preg_match("/\.php$/", $item)))
                continue;
            if (is_dir($path . "/" . $item)) {
                $target_folders = @scandir($path . "/" . $item . "/uploaded/");   
                if ($target_folders) {
                    foreach ($target_folders as $target_item) { 
                        if ((substr($target_item, 0, 1) == '.') || is_dir("$path/$item/uploaded/$target_item"))
                            continue;
                        $count++;
                    }
                }
                $count_result[$item]=$count;
            }
             echo "<tr><td><div class='data'>" .$item."
                </div></td>";
             echo "<td><div class='data1'>" .$count."
                </div></td>";
        }
    }
?>

<?php
    $counta_result=array();
    $path = "Users";
    $foldersa = @scandir("$path");
    if ($foldersa) {
        foreach ($foldersa as $itema) {
            $counta = 0;
            if ((substr($itema, 0, 1) == '.') || (preg_match("/\.php$/", $itema)))
                continue;
            if (is_dir($path . "/" . $itema)) {
                $target_foldersa = @scandir($path . "/" . $itema . "/incomplete/");
                if ($target_foldersa) {
                    foreach ($target_foldersa as $target_itema) {
                        if ((substr($target_itema, 0, 1) == '.') || is_dir("$path/$itema/uploaded/$target_itema"))
                            continue;
                        $counta++;
                    }
                }
                $counta_result[$itema]=$counta;
            }
            echo "<td><div class='data2'>" .$counta."</div></td>";
        }
    } 
?>

<?php
    $countb_result=array();
    $path = "Users";
    $foldersb = @scandir("$path");
    if ($foldersb) {
        foreach ($foldersb as $itemb) {
            $countb = 0;
            if ((substr($itemb, 0, 1) == '.') || (preg_match("/\.php$/", $itemb)))
                continue;
            if (is_dir($path . "/" . $itemb)) {
                $target_foldersb = @scandir($path . "/" . $itemb . "/processed/");
                if ($target_foldersb) {
                    foreach ($target_foldersb as $target_itemb) {
                        if ((substr($target_itemb, 0, 1) == '.') || is_dir("$path/$itemb/processed/$target_itemb"))
                            continue;
                        $countb++;
                    }
                }
                $countb_result[$itemb]=$countb;
            }
            echo "<td><div class='data3'>" .$countb."</div></td></tr>";
        }
    } 
?>
</table>
4

2 回答 2

1

1)您的实际问题的答案是您</tr>在初始 for 循环中缺少 a ,而在第二个 for 循环中缺少一个开口<tr>。所以,要么你实际上错过了这些东西,要么你的包围有问题。

2)您可能错过了这一点,因为您的代码格式不正确。如果您避免在不必要的地方“回显” HTML 块,IDE 的语法突出显示可能能够发现这个错误(取决于您的 IDE),它也会使您的代码更加清晰。

于 2013-09-18T06:14:03.477 回答
0

您正在对同一组项目进行三次迭代。第一个循环<tr>在每次迭代开始时创建 a,最后一个循环在每次迭代</tr>结束时创建 a。因此,第一个循环“正常”工作,填充前两列,然后移动到下一行。然后第二个将其所有数据放在最后一行,第三个添加数据和新行。您应该只使用一个循环来根据需要填充列,而不是对相同的数据循环三次。在每次迭代的最开始,添加一个<tr>,并在最后,添加一个</tr>

看到这个小提琴。这无权访问您需要的任何目录,因此我将scandir调用替换为array_fills,但您可以看到格式是应有的。注意:代码还有很多额外的优化;这只是为了表明将三个循环合二为一将有助于解决这个特定问题。

于 2013-09-18T06:49:53.707 回答