开发者

Problems With Tables And PHP

I'm using this code to populate a Table:

<style type="text/css">
table, td
{
    border-color: #600;
    border-style: solid;
}

table
{
    border-width: 0 0 1px 1px;
    border-spacing: 0;
    border-collapse: collapse;
}

td
{
    margin: 0;
    padding: 4px;
    border-width: 1px 1px 0 0;
    background-color: #FFC;
}
</style>

<table>
<tr>
<th>Files</th>
</tr>
<?php
foreach(new DirectoryIterator('/home/nathanpc/public_html') as $directoryItem) {
    if($directoryItem->isFile()) {
        printf('<td><tr><a href="/%1$s">%1$s</a></tr></td>', $directoryItem->getBasename());
    }
} ?>
</table>

But when I try it, what I got was values outside the table, an开发者_开发百科d all disorganized. Here it is on the server: http://surl.x10.mx/list.php


Should be instead:

printf('<tr><td><a href="/%1$s">%1$s</a></td></tr>', $directoryItem->getBasename());

tr means "table row", these should encapsulate the tds, not the other way around.


You Don't Want to Use a Table there!

You named your file 'list.php', did you? So, why not actually use a list?

printf('<li><a href="/%1$s">%1$s</a></li>', $directoryItem->getBasename());

Apart from that being shorter, it is semantic correct - which your table isn't.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜