【发布时间】:2012-07-26 05:12:31
【问题描述】:
当我创建一个循环来格式化一些 html 时:
$pieces = Equipment::find_all();
foreach($slots as $slot) {
echo "<h3>".ucfirst($slot)."</h3>";
echo "<table class=\"eq_table\"><th><td>Name</td><td>P.AC</td><td>M.AC</td><td>Saves</td><td>Dex</td><td>Str</td><td>Int</td><td>Wis</td><td>Con</td><td>Hit</td><td>Dam</td><td>Hp</td><td>Mana</td></th>";
foreach($pieces as $piece) {
if($piece->slot == $slot) {
echo "<tr><td>$piece->name</td><td>$piece->p_ac</td><td>$piece->m_ac</td><td>$piece->saves</td><td>$piece->dev</td><td>$piece->dex</td><td>$piece->str</td><td>$piece->intel</td><td>$piece->wis</td><td>$piece->con</td><td>$piece->hit</td><td>$piece->hit</td>$piece->dam</td><td>$piece->hp</td><td>$piece->mana</td></tr>";
}
}
}
我得到了这个明显不需要的输出:
screenshot http://db.tt/mtFD7Pec
页面底部有一个没有标题的额外表格。是什么导致了这种行为,我该如何解决?
【问题讨论】:
-
尝试输入border='1' 来查找对应的表格
-
你应该尝试关闭表,即你没有
</table> -
您没有在第一个 foreach 中关闭
标记(并且它的头部也缺少
)。不要内联写,格式正确,你会立刻发现它
标签: php html loops html-table