动态表(冒号取决于表的内容) [英] Dynamic table (colons depend on the content of the table)

查看:239
本文介绍了动态表(冒号取决于表的内容)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个php代码向我展示了我网站上目录的内容:

This php code shows me the content of a directory on my website:

<?php
 $dir = opendir(getcwd());
 ?>
<body>
<table>
    <tbody>
        <tr>
<?php
  while (($file = readdir($dir)) !== false) {
      {
            echo "<td>". $file ."</td>";
    }       
  }
  closedir($dir);
?>
        </tr>
    </tbody>
</table>
</body>

它将结果放在中。
问题是PHP代码生成< td> 标记并将结果存储在其中。所以最终的有一个< tr> 和多个< td> 标签,因为有结果。

It puts the results in a table. The problem is that the PHP code generates a <td> tag and store the results in it. So the final table has one <tr> and as many <td> tags as there are results.

我想要的是每行3列(3 td)(tr标签) 。

What I want to have is a table with 3 columns (3 td) per each line (tr tag).

有没有办法让表格动态,每三个< td> 标签变为a < tr> 标记
所以结果如下所示:(点击此处)

Is there a way to make the table dynamic and for each third <td> tag turns to be a <tr> tag so the results look like this: (click here)

而不是这样:(点击这里)

推荐答案

试试这个:

<?php
 $dir = opendir(getcwd());
 ?>
<body>
<table>
    <tbody>

<?php
  $n = 0;
  while (($file = readdir($dir)) !== false) {
      {
           if($n%3 == 0){echo "<tr>";}
           echo "<td>". $file ."</td>";
           $n++;
    }       
  }
  closedir($dir);
?>

</tbody>


这篇关于动态表(冒号取决于表的内容)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆