无法在div标签<table> </table>中放置标签

时间:2013-11-12 14:33:04

标签: php html css xhtml

我试图在下面的示例中放置一个标签,但是表格显示在tableWrapper div之外,tableWrapper div正确显示我想要但是表格在它之外我不明白是什么我做错了,有人可以帮忙吗? :

//the buttons 
$html .= '<p><form method="post" action = "DBTest.php" >
    <input type="submit" name="create" value="Create">
    <input type="submit" name="save" value="Save">
    <input type="submit" name="reset" value="Reset">
    </form></p>';   


//start table
$html.= '<div id = "tableWrapper"><table>';

foreach($rows as $row)
    {

         $id= $row['id'];
         $title = $row['title'];
         $year = $row['YEAR'];
        //put everything on a table
        $html.= "<tr><td>" . $row['id'] . "</td><td>" . $row['title'] . "</td><td>"  . $row['year'] . "</td><td>";
     }
$html.= '</table></div>';    

//the main body
$alpha['main'] = <<<EOD

{$html}

EOD;

这是我的tablWrapper div:

#tableWrapper{
    clear:both;
    width: 350px;
    height: 350px;
}

这是我的表css:

table {margin-bottom:1.4em;}
th {font-weight:bold;background:black;color:white;}
th,td,caption {padding:4px 10px 4px 5px;}


tbody tr:nth-child(even) td {background:#A1912A11;}
tbody tr:hover td {background:#9E9E80;}

提前谢谢

1 个答案:

答案 0 :(得分:4)

错别字:

    $html.= "<tr><td>" [...snip...] . "</td><td>";
                                            ^^^^

您永远不会关闭<tr>代码,并以新的未终结<td>结束该行。所以你最终得到了

<div><table>
<tr><td>...</td><td>..</td><td>
<tr><td>...</td><td>..</td><td>
etc...