【问题标题】:Column issue with table data arrangement [duplicate]表数据排列的列问题[重复]
【发布时间】:2013-09-26 10:15:42
【问题描述】:

我正在使用 readdir 从多个目录中获取文件名。我想知道是否有办法安排数据,以便每次启动新目录时都会创建一个新列,即


我目前的编码是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<table border="1">
<?php
if ($handle = opendir('Users/')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {


            echo '<th>';
            echo "$entry\n";
            echo '</th>';
            }
                  }
        }           
?>

<?php

 $folders = @scandir('Users');  
    foreach($folders as $item){
         if ((substr($item, 0, 1) == '.') || (preg_match("/\.php$/", $item)))
                continue;

        if (is_dir("Users/$item")){
            $target_folders = @scandir("Users/$item/uploaded/");
            foreach($target_folders as $target_item){
                if ((!preg_match("/^[.]/",$target_item)) || (!is_dir("Users/$item/uploaded/$target_item")));
                if ((substr($target_item, 0, 1) == '.'))
                        continue;
                echo '<tr>';
                echo '<td>';        
                echo $target_item;
                echo '</td>';
                echo '</tr>';
                                    }
                            }
                 }
?>
</table>
</body>
</html>

基本上我想要它做的是:

---| user1  | user2  | user3  |
---| file1a | file2a | file3a |
---| file1b | file2b | file3b |
---| file1c | file2c | file3c |
---| file1d |   ^    | file3d |
---| file1e |   |    |   ^    |
---|    ^   |  end   |   |    |
---|    |   |  dir2  |  end   |
---|   end  | #start |  dir3  |
---|   dir1 |  col3  |  etc.  |
---| #start |        |        |
---|  col2  |        |        |

如果这是可能的,那就太好了;至于在顶部显示用户名,我已经把那部分放在了下面。我只需要知道列部分是否可以完成,如果可以,该怎么做。

【问题讨论】:

  • 有什么想法吗?好像不难,就是不知道怎么安排。
  • 将 标签从循环中取出,将循环包裹在其中。接下来,将来自每个用户的所有信息转储到仍处于循环中的 标记内的每一列中,确保在每个条目之后添加一个中断
    就完成了。
  • 不,这似乎不起作用

标签: php arrays while-loop html-table multiple-columns


【解决方案1】:

通过以下代码实现:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
echo '<table class="table"><tr>';
$folders = @scandir('Users');  
    foreach($folders as $item):
     if ((substr($item, 0, 1) == '.') || (preg_match("/\.php$/", $item)))
                continue;
    ?>
    <td align="top">
          <table width="220" border="1" valign="top">
               <tr><th width="210" valign="top"><?php echo $item;?></th></tr>
              <?php
               if (is_dir("Users/$item"))
            $target_folders = @scandir("Users/$item/uploaded/");
                foreach($target_folders as $target_item){

                if ((!preg_match("/^[.]/",$target_item)) || (!is_dir("Users/$item/uploaded/$target_item"))){
                if ((substr($target_item, 0, 1) == '.'))
                   continue;     

                   ?><tr><td><?php echo $target_item ;?></td></tr><?php

                }
                }

                   ?>
          </table>
</td>
    <?php
endforeach;

echo '</tr></table>';
?>


<style type="text/css">

    td {
vertical-align: top;
}



</style>
</body>
</html>

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签