我正在通过 php 在 mysql 数据库上运行查询。使用我的结果集,我正在迭代下表:

        $resultString = '<table>';
        $resultString .= '<tr>';
        $resultString .= '<th>Index</th>';
        $resultString .= '<th>Title</th>';
        $resultString .= '<th>File</th>';
        $resultString .= '<th>Template File</th>';
        $resultString .= '<th>Pretty URL</th>';
        $resultString .= '<th>Parent</th>';
        $resultString .= '<th></th>';
        $resultString .= '</tr>';

        while($data = mysql_fetch_assoc($results)){
            $resultString .= '<form class="myForm">' ."\n";

            $resultString .= '<tr>' ."\n";

            $resultString .= '<input type="hidden" name="index" value="' . $data['index'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="title" value="' . $data['title'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="file_name" value="' . $data['file_name'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="template_file" value="' . $data['template_file'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="child_of" value="' . $data['child_of'] . '">' ."\n";
            $resultString .= '<input type="hidden" name="pretty_url" value="' . $data['pretty_url'] . '">' ."\n";

            $resultString .= '<td class="indexTd">' . $data['index'] . '</td>' ."\n";
            $resultString .= '<td>' . $data['title'] . '</td>' ."\n";
            $resultString .= '<td>' . $data['file_name'] . '</td>' ."\n";
            $resultString .= '<td>' . $data['template_file'] . '</td>' ."\n";
            $resultString .= '<td>' . $data['pretty_url'] . '</td>' ."\n";
            $resultString .= '<td>' . $this->get_parent_select_list($data['child_of'],$data['index']) . '</td>' ."\n";
            $resultString .= '<td class="buttonTd"><input type="button" class="deletePageButton" value="X" onclick="submit_form(this,\'deletePage\')"></td>' ."\n";

            $resultString .= '</tr>' ."\n";

            $resultString .= '</form>' ."\n";
        }

        $resultString .= '</table>';

表格很好,唯一的问题是我的表格根本不起作用......在 FireBug 中查看它我看到了这个:

表单正在关闭,因为我所有的输入标签都可以填充它。我曾尝试将标签放在“”而不是“”中,但无济于事....

想法?

最佳答案

当您在另一个标签中打开一个标签时,您打开的标签将在其父标签关闭时关闭。所以这:

<p><form></p>
<p></form></p>

将(或应该)导致:
<p><form></form></p>
<p></p>

您应该在表格上方打开表格并在底部关闭表格,从而将整个表格包含在表格中。

在 tr、td、thead、tbody、tfoot 或 th 标签之间放置非表格标签是不好的做法,不符合 w3c

关于php - 表格问题(在表格中提前关闭),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3687258/

10-14 14:37
查看更多